-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-sizing] How to shrink to fit the width? #191
Comments
I think the best would be to adjust Sebastian |
@SebastianZ That would be best. |
No, fit-content() won't work here. fit-content is "try to be max-content size, clamped by min-content and the specified limit" (or in the case of the Tight wrapping has been discussed in the past, but has never made it in yet. |
On 06/22/2016 02:10 AM, Tab Atkins Jr. wrote:
See discussion at https://www.w3.org/mid/54DAAD2C.6060704@inkedblade.net ~fantasai |
I have the same issue on one of my sites, as I tried to explain here. And today the CSSWG Twitter account told me that it’s been discussed here on Github. Hurray! I was wondering, is there any progress on this? |
No progress yet, though we're glad to have your use cases tracked here. :) I think the blocker here will be largely the difficulty for implementations in doing something relatively difficult and expensive, so seeing where it's needed is helpful to justify the effort. |
Please add this option. I also need it. JS solution is complicated because during resizing window there must be made additional steps... |
I love that some problems like this one still don't have a solution with today's CSS. Does it represent a challenge (cyclic dependencies)? Does it lack use cases / demand from developers? Here's a use case I had today: https://codepen.io/benface/pen/WYMMPo I don't want the underline to go past the text. Easy when the text doesn't wrap (a simple I'll be following this one for sure. |
Yes, it's cyclic in general - the container size depends on the layout of children, but children layout depends on the size of the container. In restricted cases you can of course solve this, but not in general. |
I run into the issue constantly when building site navigation. 😫😢 Codepen of the screenshot found here: Note: I use |
https://codepen.io/argyleink/pen/wvjeOdz What I believe we want is shrink wrapping, and i mean that in a tricky way, we want it to shrink the inline size to fit the content AFTER wrapping has occurred. Some way to specify this inline-size or post-wrapping task would be really nice. |
Just want to drop here that this is something I also always wanted. One thing I want to add — when looking and playing with This way, it won't be super perf intensive for more complex cases, but would be simple enough to handle for most of the cases where you'd want it (usually the more there is content, the more likely it would take the full width when wrapping). Related issues: #8516 and #3070, as I think this one and those two have the similarities in the possible limitations. |
Related discussion on Reddit: https://www.reddit.com/r/css/comments/16c9gmh/how_can_i_remove_this_horizontal_spacing_when_a/ |
I just published an article that explores how anchor positioning can be used to partially solve these kinds of issues: https://kizu.dev/shrinkwrap-problem/ So, when anchor positioning eventually becomes available, it will help with some use cases. Not all of them — there is still room to explore how the proper native solution could look like. But my exploration of this did show that it is very far from being a trivial problem, and when involving more complicated code it is easy to end up with circularity issues (hence, why we don't have any good way of handling this yet). |
That is awesome, @kizu! Great work. |
@tomasdev I don't understand what you are advocating for in your expectation. There is no logical reason for the text to wrap at the point it does in your expectation. It wraps the way it does currently because min-content shrinks the container to the smallest width possible without causing content to overflow out of the box. |
@tomasdev It sounds lke you want grid-template-columns: minmax(min-content, max-content) max-content auto; That's unrelated to the problem here. |
It's hard to tell what you want, your "inverted in a way" might have mislead me. If you want
Then the 1st part works with |
I’ve been using Not sure it's useful at this point, but here is another testcase: https://codepen.io/leaverou/pen/MWRZVJv FWIW, I had also expected |
Made another small demo using my anchor positioning way of doing the shrinkwrap (so obviously only visible in Chrome Canary): https://codepen.io/kizu/pen/LYvqPmO?editors=1010 Here is a video, showing 5 items, each having a max-width of 20% of the parent's width, with Screen.Recording.2024-04-24.at.11.22.45.movWith this method (and I imagine with any other similar one), for every element with shrinkwrap we need to know its dimensions before layout out every other element that depends on it. This can lead to very complex calculations if used for many elements, which is probably one of the reasons this does not exist in CSS yet (and I doubt it could, but we can dream, I guess). |
This was a very interesting and creative article, but still too hacky and un-supported for me to use in real use cases. I would highly recommend anyone stumbling on this issue to use this (pretty simple and clean) JS-only solution for now: |
Was going to switch from |
In this demo: http://jsbin.com/weqapufoyi/edit?html,css,output
Because span float will automatically wrap, how to make the parent element shrink to the "Expectation" effect.
Can we add a new width/height value(e.g.
width: auto-shrink
), or already have other solutions?spec: https://drafts.csswg.org/css-sizing/#width-height-keywords
cc @dholbert @tabatkins @fantasai
The text was updated successfully, but these errors were encountered: