CSS3 Feedback: Layout
Published 15 years, 10 months past(This is part of the Feedback on ‘WaSP Community CSS3 Feedback 2008’ series.)
In this round, layout. Not all of it, but the bits that struck me as either really useful or really, really way too long overdue.
Float containment — yes, we need a property that does just that. As long as we’re tied to floats for layout—and I plan to rant about that soon—there should be a clear, unambiguous, intentionally defined property that tells elements to wrap themselves around floated descendant elements. overflow
works in most cases but can fall down in unusual circumstances (I’ve seen scrollbars appear where none were actually needed) and anyway, it wasn’t intended to provide the wrapping effect in the first place. That it does so is a happy side effect, but it’s still a side effect. The rest of the float-wrapping techniques are even more convoluted. “There are already ways to do that so we don’t need a property” is rather like saying “we can already do layout with tables so why do we need CSS layout?”.
Positioning by center — yes, please. The way to center an absolutely positioned element within its containing block is to set the top
and left
to 50%
each and then define negative top and left margins that are half the positioned element’s height and width. That’s just awful, and requires at least an explicit width, if not an explicit height. When I did the structured timeline, here’s how I got the version numbers to center below the dots:
#timeline tbody td p { position: absolute; top: 50%; width: 2.1em; margin: -5px 0 0 -1em; }
See that -1em
left margin, and the 2.1em
width? Just to get the center of positioned elements’ boxes sit on top of a certain left offset (defined elsewhere in the CSS). Ditto the negative top margin, to pull it upward just enough so that the elements’ boxes would have the point five pixels down from their tops line up with the vertical midpoint of their containing blocks.
I wanted to do something like this:
#timeline tbody td p { position: absolute; top: 50%; position-anchor: 50% 5px; }
That would have said that the point in the center of the absolutely positioned element should be placed at the point in the containing block 21.7% down from the top and 44% of the way across from the left. That would hang the positioned element’s center on that point, regardless of the size of the positioned element—note that I took out the width
. I could stop defining explicit sizes and just let the elements be the size they want to be to show their content.
The problem is that approach doesn’t fit at all well with the way positioning layout is defined. Suppose I said this:
#timeline tbody td p { position: absolute; top: 50%; bottom: 0; left: 50%; right: 25%; position-anchor: 50% 5px; }
Now what? I’m not even sure myself. Maybe define rename it to position-offset
and define percentages to be relative to the height and width of the positioned element (not its containing block), so that it doesn’t interact directly with the offset properties like top
and right
?
All I want is a way to hang elements off of offset points, and not be restricted to the corners of the elements, and have the solution work even when the elements have automatic height and width, and not require extra markup to make it happen. Oh, and a ponycar.
Box sizing — what in the nine hells of Valeria is taking so long? We needed that one ten years ago. I no longer care if it’s done as its own property or as new keywords on height
and width
. I just want it. Someone will make it happen, with or without the WG or implementors—mark my words.
Same-height elements — yes, a way to tie element heights (whether they’re siblings or not) together would be welcome, although I can see how specifying it in an implementable would be tricky; no, display: table-cell
is not the answer. Soon I will rant about this. Soon.