-
Notifications
You must be signed in to change notification settings - Fork 717
Proposal: a way to enable margin-collapse on BFC? or a new type of context like BFC but with margin-collapse? #6752
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
Comments
If I'm not mistaken, the |
Thanks, and I think you're right. Hope it gets implemented. |
If you want a BFC but remove the start and end margins of the contents, But otherwise it sounds like you don't actually want BFC, you only want to clear floats. Why not use a "clearfix", then? ul::after {
content: "";
display: block;
clear: both;
} |
Thanks for the reply. It's possible I misused the word clearfix, because the old-school solution you have there actually doesn't address the problem I'm talking about, which I realize now I should have explained more clearly. Say you have this markup: <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, blah blah blah ...</p>
<ul>
<li>I am a list item</li>
<li>I am also a list item</li>
</ul> with these styles: p {
float: left;
width: 10rem;
}
ul {
list-style: none;
}
ul li {
position: relative;
padding-left: 1em;
}
ul li::before {
position: absolute;
left: 0;
content: "•";
} You end up with the absolute-positioned bullets all the way over to the left, overlapping the floated paragraph: The traditional clearfix you mentioned doesn't work here, but |
Here is another example, where a left-border causes the same kind of problem: <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, blah blah blah ...</p>
<blockquote>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</blockquote> p {
float: left;
width: 10rem;
}
blockquote {
border-left: 4px solid black;
padding-left: 1em;
width: 15rem;
} Here again, |
OK, then But rather than introduce the concept of "like BFC root but with margin collapse", I think it may make more sense to add a property to force a block to not overlap floats in the same BFC, without forcing it to establish a BFC. It could be like |
Yes, |
It would be useful to either:
display
value that creates such a context, much likeflow-root
does with BFC).Here is the problem that this would solve:
In prose/WYSIWYG situations—where the developer isn't in control of the order that various elements end up appearing in—some kind of "clearfix" is often needed to prevent certain elements from "overlapping" a floated neighbor. A typical example would be when a left-floated image ends up next to a
ul
whose bullets are styled as absolute-positioned::before
pseudo-elements on theli
s.The modern way to implement the "clearfix" is to give
display: flow-root
to the elements that create a problem if adjacent to a float. Doing so, however, creates a new BFC on the elements in question, thereby suppressing margin-collapse on them. This is a problem because margin-collapse is extremely useful for maintaining consistent vertical rhythm in these WYSIWYG contexts.One can more or less work around this by "undoing" the outward-facing margins at the extremities of the
flow-root
element's interior, so that only the vertical-margins of the element itself remain:but it's ugly and, worse, unreliable (it only works for however many layers of
> :first-child
/> :last-child
you include).In short, the suppression of margin-collapse prevents
display: flow-root
from being a satisfactory "clearfix" solution in many situations. To my mind, what's missing is the ability to opt in to margin-collapse for a BFC (or to create a new type of context just like BFC but without the suppression of margin-collapse on the root).The text was updated successfully, but these errors were encountered: