-
Notifications
You must be signed in to change notification settings - Fork 687
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-align] behaviour for width or flex-basis of flex items when gap applied to flex container #2668
Comments
On flexboxes the |
It is really frustrating to talking to you. Do you ever stop to consider what someone might be trying to say before coming to your conclusions? I meant what effect does the |
Here's an example. If I do this
Does this mean that the flex items will not sit on one line because the gap would push them onto two lines? There is no clarification in the spec that I can find that explains what happens in this scenario. Grid is a different concept to flex as in it sets up a template grid on the container and the author can specify where items should line up on that grid. Flex doesn't have the same concept and so there is no way I can think of for the author to accommodate the gaps unless the width or flex-basis automatically accounts for the gap, or there is another way to accommodate for them. |
Apologies for any perceived rudeness. Your question was asking about The details of If you're using % widths, tho, you generally already know how many items fit on a line, and can use margins to produce gaps on your own (and make sure that, for example, all the %s add up to 100%). |
It's ok. It just makes me feel like I don't know what I'm talking about and I felt like I was waisting your time. I hope my reply didn't come across too impolite either. You're right in my example, it will make the items push out further than the width of the container. I meant to put It's fine if the proposal is that gap has no effect on how %s resolve although I think we might be missing out on allowing authors the control they need. One advantage flex has over grid is that it's content can influence the layout. Setting a width on the items inside the flex container can change the overall layout, especially if One use case is if you wanted to have the contents of the flex container dictate their own sizes and therefore effect the layout of the whole container. This can be useful for layouts where the size of the content is important. Flex items can be added and removed and will allow content to adapt as needed because it is fluid. As a designer I would want this content to align to a grid with columns and gutters and it would be annoying to have to minus the gap from the width for it to line up correctly. Also does flex-basis work on the basis that it takes up the available space This brings me to my next point which is why don't we allow I started working on a PostCSS plugin a while ago that tries to help with creating gutters and then that's when I saw that there was a proposal to allow the gap property to work for flex boxes also. Now I'm considering changing it to be more inline with the draft spec so that it could maybe be useful as a polyfill. It would be good to get your eyes on it as I'd like it to adhere to the spec as close as I can. It works with nested containers which I found an interesting challenge when it came to mixing containers with gaps in pixels and gaps in percentages. Would love to get your thoughts. |
Correct, but that underlines the other big difference between Flexbox and Grid - the width of a grid item has no effect on which row it ends up on, only the span does. Thus if the space is reduced by This is why taking the gap into account when calculating %s on flex items is hard — the number of gaps affects the space available, but the space available can affect how many items will fit on the row, which affects how many gaps there will be. (It's not impossible to resolve this — we solve the exact same problem for
Trying to get a multiline flexbox to act like a grid is always going to be problematic. You can sometimes do it, but it'll always be somewhat fragile and hacky; it's not what the layout mode is designed to do. You should really be using Grid for this. It sounds like you might be asking for "make this grid item automatically get an appropriate span, according to its size", which is tracked in #1373.
The most straightforward answer is "because margin-collapsing is already complicated enough". Flex items, grid items, and multicol columns don't have collapsing margins; their margin boxes are treated as inviolate and don't overlap by default. Thus it's easy to put a gap between those margin boxes. Blocks don't behave this way — they collapse adjacent margins together, so there's no good notion of "between" where we could place the gaps. We could disable margin collapsing when you use gaps, perhaps, but that would be relatively disruptive. Margins generally work fine, as blocks are single-line. The one place they're awkward is when the container has border/padding, and so the first and last children's margins can't collapse outside of the container; you then have to manually target them and set their top/bottom margin to For inlines, we already have a property that's basically identical to <!DOCTYPE html>
<div class=one><span>foo foo</span> <span>bar bar</span> <span>baz baz</span> <span>qux qux</span></div>
<div class=two><span>foo foo</span> <span>bar bar</span> <span>baz baz</span> <span>qux qux</span></div>
<style>
div { word-spacing: 1em; border: thin dotted; margin: 5px; }
div.two { width: 200px; }
span { display: inline-block; word-spacing: normal; }
</style> Here, we use word-spacing to create a "gap" of 1em between the spans, which works properly when the text wraps (no annoying gap at the beginning or end of the lines). We just have to be careful because the property inherits, so you need to reset it to |
Yes I think this would solve that use case.
Yes the |
Actually there is one scenario I don't think issue #1373 will solve. That is when the designer is best to dictate the number of columns a item should span rather than the length/amount of text dictating it but they are unaware of what content will be sat either side of the item. |
Hi. Are there any details around what affect of the proposed
gap
properties for flex containers might have onwidth
orflex-basis
if any? With CSS grid layout the author can use thespan
value but flex items have no concept of columns so I'm wondering how an author might specify the width/span of a flex item and account for the gutters/gap also?The text was updated successfully, but these errors were encountered: