671 points · by oskarth · 11y ago · 123 comments
https://github.com/philipwalton/flexbugs
A community-curated list of flexbox issues and cross-browser workarounds for them.
Thank you for doing all this, that really helps spreading the word and accelerates web development!
This makes feel the project more interesting, because if I hit one of the already covered problems, I already know where I can (probably) find the solution.
As far as I know support on Safari wasn't quite there yet. Last when I checked, and that was almost two months ago, Flex broke down pretty badly on iOS Safari, both on iPad and iPhone.
Guess I need to revisit this probably. Thanks for the great piece of work!
Regarding flexbox itself: the syntax is confusing. After working on html/css, leaving, using auto-layout (obj-c, ios) and coming back to trying flexbox, I am scratching my head, who came up with this?
row/column - use horizontal/vertical or hor/ver for short. justify-content and align-items mean different things depending on whether you're using row or column - what?
why not just have hor-align, ver-align?
Suppose you want a box with 3 paragraphs left-aligned, centered on the screen and a footer with 1 paragraph, aligned with the 3 paragraphs above it, how do you do this?
Here's my pseudo-code:
body ver nowrap, hor-align center.
add 2 flex boxes ver nowrap.
box 1 height stretch, hor-align left, ver-align center.
box 2 height fit-content, hor-align left, ver-align center.
add 3 paragraphs to box 1.
add 1 paragraph to box 2.
In reality, it is: body flex: column nowrap, justify-content: center, or is it align-items? I don't know, let's guess.
How do I do box 1 height stretch? Hm... I don't intuitively know because nothing intuitively makes sense with flexbox. The answer turns out to be flex: 1 on box 1 and flex: 0 on box 2. Great syntax.
And the pain continues. Btw, if you set the paragraph margin to 1em 1em 1em 1em;, it breaks the horizontal alignment of the paragraphs, making them center-aligned, why? Only God knows. If you set margin: 1px 1px 1px 1px, it works as expected. What?!
Flexbox is light years ahead of the retardation that is floats and clears and the rest of it but it is a FAR cry from auto-layout.
Let me set the height of an element... in relation to another element... ANY element... Why am I doing flex: 2, flex: 1 but that only works for sibling elements? What if I want box 1 width to be 20% of the height of box 2 that's elsewhere on the page? How do I do that in flexbox?
Even if there is a way, the fact that I don't know and I've spent 2 days figuring it out says it all.
As others have mentioned, being able to switch the orientation of the principle axis is very helpful, for example when going from a row to a column on mobile. Because all positioning is defined based on the principle axis, all the styles translate correctly, and you don't have to override 4+ different rules.
> How do I box 1 height stretch? Hm... I don't intuitive know.
If you understand how align-items aligns everything else along the secondary axis, then "align-self: stretch" seems pretty intuitive (http://codepen.io/conlectus/pen/WvGLvy).
> re: 1em margin breaking alignment
I'm not sure what you're referencing here, as it seems to not do that http://codepen.io/conlectus/pen/WvGLrK
A guess would be that you don't have box-sizing: border-box on all elements set.
Adding "flex" always makes the element take up as much space as it can, and the number specifies how much "force" it applies compared to other elements.
I think I'm just ranting on the html layout rules in general, for instance:
https://css-tricks.com/almanac/properties/m/margin/
This points out like 3 things that make NO SENSE. To center something horizontally, you use margin: auto; What? Margins are for having space between elements, not for centering anything. But ok let's say it is for centering, which makes no sense, then you should be able to set the vertical margins to auto. Wait, you can't do that. WHAT!?!
It goes on to say if you have 2 paragraphs with top and bottom margins, that doesn't mean you have 2 paragraphs with top and bottom margins some of the time. Because 2 paragraphs, the top/bottom margins of the 2 paragraphs will collapse. WHAT?!?!?!?!
Yeah, flexbox is just another abysmal attempt, in the right direction mind you. I don't know who runs the show but I'd say a 3rd year comp-sci student in one year, can come up with a better layout engine (how it works, not performance, by copying auto-layout for instance) than what is currently in existence.
Link to the Flexbox spec for anyone interested:
And margin collapse was a bad idea, I agree. But HTML had it, before CSS. If anyone is to blame for margin collapse, it's NCSA Mosaic. CSS just needed to describe what already existed.
But it seems that w3c has something in common with war: it never changes.
If you want horizontal and vertical alignment to switch places when you change directions, then you can have a flag that does that for you.
For example I have X | X | X - a horizontal layout. I want it left-aligned horizontally and top-aligned vertically. (Top-left corner) and I make it work with the current flexbox stupid syntax.
Now if we switch that to vertical layout
X
-
X
-
X
Now where is it gonna be with the current flexbox layout and using content-whatever align-items? I don't really know off the top of my head, because it doesn't make intuitive sense!
With horizontal/vertical I know it's in the top left corner. With flex-start, justify-content and align-items I don't know what the heck.
Switching orientation is a basic requirement for the whole idea of flexible boxes in CSS. From MDN [0]:
> The flexbox layout algorithm is direction-agnostic as opposed to the block layout, which is vertically-biased, or the inline layout, which is horizontally-biased. While the block layout works well for pages, it lacks sufficient definition to support application components that have to change orientation, resize, stretch, or shrink as the user agent changes, flips from vertical to horizontal, and so forth.
[0]: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexi...
See this article at CSS-Tricks for some examples https://css-tricks.com/using-flexbox/
I think "margin: auto" maybe should have been written "margin: center" to make it more obvious, but the feature is there.
Just center the div in absolute mode. You need to have it wrapped in something though, to have something to center against, but you shouldn't have tables in there unless you want them.
In the "individual grid sample" why have you chose to make a 2/3rds and 1/3rd column with divs respectively
flex:1; width:33.3333333%
instead of leveraging the ratio flex:2; flex:1However if you set flex-basis to zero then it will treat the element as if it was zero width for the purposes of calculating its new size from.
So if all elements have a zero basis then the flex ratio will be the only thing affecting their final width:
If I'm wrong, I'll gladly take 100 downvotes in exchange for a link to a resource that has flexbox-driven horizontal masonry instructions.
http://demosthenes.info/blog/844/Easy-Masonry-Layout-With-Fl...
1 4 7
2 5 8
3 6 9
So, no, that doesn't solve the problem.One thing to help complete the story: could this page link to a flexbox polyfill for older browsers?
http://re-demo.s3-website-ap-southeast-2.amazonaws.com/#/h-b...
Definitely try out the Show me: on the bottom. Also try checking out the checkboxes in the gray box, as well as changing the values.
Browsers are getting upgraded in general, but you still get government-x and company-y asking for IE7 support.
We have a phantom measurement of 3% IE7 usage when the actual usage is 0% (our web app prevents IE7 users using JavaScript because it is too broken). The measured IE7 users are actually using IE8 (as a control embedded within a Windows exe, actual usage measured using @cc_on @_jscript_version).
Pure CSS runs in the browser without a get request (other than the CSS file you are already using, obv.) so it eliminates the need for a grid system like Bootstrap, 960gs etc. The 'grid' is there in the CSS and html where it is meant to be, without the need for @media queries with 10 decimal points and 15 font sizes. It also provides more layout options than currently exist without the need for hacky solutions.
How useful the linked site is right now is questionable though. If you want a IE8+ cross browser & mobile site to rely on flex-box ... it can be done and quite easily, but not with the skeleton examples on that page (but they do point that out themselves).
Basically, constraint solving is harder to understanding, doesn't support wrapping, and is slow.
Because from what I've seen/heard, the Cassowary constraint solver is used extensively in Mac OS X/iOS for UI layout, which AFAIK isn't really referred to as slow.
Plus the constraint solver does operate on a matrix of constraint, which should make it easier to work on GPU.
It is not natively implemented however. Also, to take it further, Cassowary.js could solve for and output to flexbox as a backend.
With https://wiki.css-houdini.org/ there is a chance you could implement custom layout in CSS.
I've recently looked into flexbox for a project I started, but all the examples and stuff out there seem very ambiguous (compared to the amount of time I'm willing to invest. I just want things TO WORK). But looking at those docs again with this will help my understanding heaps.
It is an elegant approach to very common layout problems without any libraries, plugins, or javascript.
The whole point of markup and CSS is to solve the layout stuff for you. Javascript should be mainly for data transformation.
When you throw in web components and two-way data binding via object.observe, we can approach this ideal separation of concerns.
What performances issues are you talking about?
With vjeux's css-layout library, adoption from React Native on iOS and Android and mentions of perhaps adopting it in AsyncDisplayKit, Flexbox is becoming a valuable layout system to be familiar with.
1 4 7 10
2 5 8 11
3 6 9 12
Other than than columns, which dont respond the screen size that well, this is the only good option. Thanks for educating me!The ubiquity of the "funny == upvote" mentality is rather depressing, and I'm glad that HN (generally) tries to avoid that. It makes the comments section a much more interesting place to be (to me, at least).