123 points · by pmontra · 9y ago · 78 comments
Why is the unhacked behaviour desirable? If I put a thing in a thing, surely I want it to stay in the thing?!
Here's a demo: http://codepen.io/anon/pen/ggGgWb
Here's the "clearfixed" version which is nonsensical: http://codepen.io/anon/pen/xgXgry
That floats were press-ganged into layout does not mean their basic behaviour is bad, it just means they were used for something that was never intended (due to a lack of actual layout tools in CSS until CSS3) and they were not very good at it.
And note that the lack of layout tools was not limited to "applicative" layouts, most papers are laid out in multiple text columns yet that fairly simple and common layout was not supported either until CSS3.
You cannot have a div that is both `display: inline-block` and `display: flow-root` at the same time, for example.
That's really not true[0], "display: flex", "display: grid" or "display: table" are all inner display properties, which is why inline-flex, inline-grid or inline-table exist ("display: flex" sets the outer display mode to "block" and the inner one to "flex", "display: inline-flex" sets the outer display mode to "inline" and the inner one to "flex").
Which is why CSS3 split display properties between outer display (block, inline or run-in) and inner display (flow, flow-root, table, flex, grid or ruby), which can be specified independently e.g. `display: inline flow-root`.
Furthermore `display: inline-block flow-root` makes no sense
1. `inline-block` is specifically a "legacy" display property which impacts both inner and outer display (and thus is not compatible with a separate inner display property)
2. `inline-block` already means `inline flow-root` so `display: inline-block flow-root` would expand to `display: inline flow-root flow-root`
[0] and has not been since CSS2 and display: table, possibly CSS1's display: list-item
Furthermore there are values which have more complex interactions/natures than just inner/outer e.g. "contents" (which removes the element's box but leaves the descendants — including pseudo-elements), "list-item" (which can be combined with any outer type but only the flow or flow-root inner types, and generates an internal pseudo-element), or the "internal values" which only make sense within wider display context (table and ruby).
About the only reason I can think of off the top of my head is that you / your team already fully grok floats, they are sufficiently powerful for your use case, and you don't want to invest the time to learn flexbox to achieve the same outcome as you could already achieve.
The linked article uses an image floated left, with text wrapping around it. Curious to know how you'd [sanely] accomplish the same result in flexbox?
Floats aren't just for structural layout. Even with 100% browser support for Flexbox, I'll still be floating some things.
In fact floats aren't for structural layout at all, they were used for it because there were no structural layout tools available at the time.
.container {
display: table;
width: 100%;
}
See bottom example here http://codepen.io/jrf0110/pen/xgXPGjI've never had to use the clearfix hack (that's probably a lie, but I can't recall a time in my career where I didn't just use the display: table; width: 100%; method)
It looks like the difference may be some legacy IE6 thing.
In ancient times some browsers required setting a width or height as well.
For example, consider a feature like arrow function support in JavaScript: http://caniuse.com/#feat=arrow-functions Click "usage relative" to scale by the relative popularity of different browser versions.
Despite only being standardised and implemented in browsers last year, arrow functions are already supported in the large majority of deployed web clients, including Edge, Firefox, Chrome and Safari, both desktop and mobile.
Nowadays, new features, particularly relatively small and uncontroversial ones like display: flex-root, can get implemented across browsers very quickly.
It still is largely true unfortunately.
IE10/11 are at about ~4% global usage. Less than Opera Mini. And a large number of those users will have access to another browser. We've found many enterprises keep IE around to access legacy services, but let people install Chrome in order to access things that need a modern browser.
The days when it was worth supporting IE for new development work has long since passed. Company policies that mandate doing so should be challenged as a waste of time and money.
Nowadays I don't use floats anymore. Flexbox is the current layout recommendation and I encourage you not to create legacy CSS stylesheet layouts with float.
'Some people, when confronted with a layout problem, think "I know, I'll use floats." Now they have two problems.'
Not until all browswers support it.
If making a polyfill is the solution, we risk ending up with a bigger polyfill file than the actual CSS implementation in the browser. If that is the case we can better do styling with JS.
I've had difficulties implementing similar things in the past.
(Obviously: starting from date supporting old browsers costs more than supporting them brings in, which depends on your product and your customers)