11 ms·
Flexbox in 5 minutes
- pi-rat 12y agoDoesn't work properly in safari, seems to be missing the -webkit prefixes (still..) required by safari. :/
- robin_reala 12y agoNot that this helps the demo, but for your own apps autoprefixer does a good job of polyfilling in the previous versions of flexbox that are still hanging around (assuming you’ve got a build chain): https://github.com/postcss/autoprefixer https://github.com/postcss/autoprefixer
- masklinn 12y agoFor playing around or to accompany tools/systems without an assets pipeline, Lea Verou's prefixfree[0] works very well, it does not require a compilation/munging phase and only generates the necessary prefixes for the browser it's run into. Really quite convenient. [0] http://leaverou.github.io/prefixfree/ http://leaverou.github.io/prefixfree/
- freshyill 12y agoI'm working on a major redesign right now and working heavily with Flexbox. Between all the prefixes and the display: table fallbacks I'm using for old IE, there's a lot to manage. Autoprefixer's value really becomes obvious when dealing with Flexbox. Flexbox is unique because it's not just vendor prefixes, but two previous specs that you need to manage. I really couldn't build a large site without it.
- _devbryce 12y agoSorry about that. When I first built this (many moons ago) it was unreasonably difficult to get it working in Safari. Sounds like it's time to revisit that issue.
- didgeoridoo 12y agoGreat method of explaining flexbox — most non-interactive explanations end up looking like Mondrians (and convey approximately the same information). Unfortunately, this demo melts down in Safari, which still requires prefixing.
- masklinn 12y agoFor some reason, it does have the very annoying behavior of resetting element height when altering align-items.
- dceddia 12y agoYes, I ran into this bug as well. Another small bug, slide 13: "...while we've got these three fixed-width items here, take a minute or two to explore the container styling options at the top of the page." The container styling options are in the middle-right of the page, at least on my desktop browser.
- davedx 12y ago"Amazing! What used to require an entire suite of floats, media queries, and outright hacks, is acheived by adding one property to a container div!" ...or you can just set display: inline-block on the child elements... [1] [1] http://jsfiddle.net/18fjgc0w/ http://jsfiddle.net/18fjgc0w/
- treerock 12y agoTried inline block a few times but find the spacing on inline elements (and the various workarounds[1]) a bit awkward and unpredictable. [1] https://css-tricks.com/fighting-the-space-between-inline-block-elements/ https://css-tricks.com/fighting-the-space-between-inline-blo...
- masklinn 12y ago> ...or you can just set display: inline-block on the child elements... [1] Which requires various hacks or source-munging to remove word-spacing between your elements, and fix baseline spacing.
- Igglyboo 12y agoAmazing, I had always heard flexbox being touted as the "next big thing" but it had come across as confusing and obscure. This was a great tutorial and I will definitely be using flexbox in the future. It seems to almost eliminate the need for a grid system a la bootstrap, which is great because I know a lot of people that use bootstrap specifically for the grid system and throw out/re implement all of the other parts.
- masklinn 12y ago> It seems to almost eliminate the need for a grid system a la bootstrap Having classes/mixins is convenient, rather than need to implement the properties "by hand" all the time. But it does get rid of most of the complexity and compatibility issues, and provides additional features (source-order independence, column-major display, ...)
- Alex3917 12y agoFor what it's worth, the tradition wisdom is that flexbox is meant for widgets (e.g. the social icons in your sidebar), not for the main layout of your content.
- nailer 12y agoThe FB CSS replacement (sorry, can't remember what it was called) used it for nearly every block element.
- nostrademons 12y agoTraditional wisdom gets overturned awfully quickly when people find out that tools can be used in new ways.
- krebby 12y agoNo way. It's great for layouts too, particularly the ever-difficult fluid-3-column-on-desktop-to-one-column-on-mobile "holy grail" layout [0]. That site has a few other great examples like media objects that would usually take a ton of CSS hacking but are solved easily with flexbox [1]. [0] http://philipwalton.github.io/solved-by-flexbox/demos/holy-grail/ http://philipwalton.github.io/solved-by-flexbox/demos/holy-g... [1] http://philipwalton.github.io/solved-by-flexbox/ http://philipwalton.github.io/solved-by-flexbox/
- pestaa 12y agoAccording to http://caniuse.com/#feat=flexbox http://caniuse.com/#feat=flexbox it is already widely deployed. Why did I wait?
- janfoeh 12y agoIt is lovely, and I wouldn't want to miss it anymore. But the spec is still somewhat fluid, and I occasionally run into unpleasant edge cases like this one: http://stackoverflow.com/questions/28563384/flex-basis-webkit-blink-ignore-intrinsic-aspect-ratio http://stackoverflow.com/questions/28563384/flex-basis-webki...
- robin_reala 12y agophillipwalton keeps a list of flexbox implementation bugs here: https://github.com/philipwalton/flexbugs https://github.com/philipwalton/flexbugs Hopefully the day will soon come when I don’t have to refer to it.
- janfoeh 12y agoYes, I got in touch with him through that repo; he was then kind enough to follow up on www-style and answer my SO question.
- untothebreach 12y agoAFAIK the only current reason to wait is IE compatibility. Anybody know of a shim?
- itsbits 12y agono proper supprt in IE10.. is there any hope that Microsoft will make their new Browser evergreen???
- asyncwords 12y agoIE10+ is already evergreen by default and should automatically update to IE11 (assuming the user didn't turn off auto-update).
- deleted 12y ago[deleted]
- teraflop 12y agoSo, based on a little experimentation, it seems like "align-items" and "align-content" behave identically, except that "align-items" is only used when there is one row of boxes and "align-content" is only used when there are multiple rows. I find it hard to imagine a case where I'd want the alignment to suddenly change based on how my elements happened to be wrapped. Is there ever a situation where this wouldn't be confusing? And if not, why do these two separate properties exist? (Also, I like this tutorial but there are some race conditions in the implementation. Clicking the "next slide" arrow too fast just replays the fade-in animation instead of advancing the slide. And on slide 30, if you click the "make a menu" link at the wrong time you can end up with the "flexbox in 5 minutes" intro text displayed on top of the boxes.)
- masklinn 12y ago> So, based on a little experimentation, it seems like "align-items" and "align-content" behave identically, except that "align-items" is only used when there is one row of boxes and "align-content" is only used when there are multiple rows. > why do these two separate properties exist? Because they don't behave identically: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ https://css-tricks.com/snippets/css/a-guide-to-flexbox/
- gknoy 12y agoThank you for the explanation. The guide just said "Play with them ...", so it was not obvious (at least to me teraflop) what was different about them.
- rburhum 12y agoI remember fantasai working really hard looking at her computer a few years ago (in a coworking space at SF). I asked her what she was working on - and she replied "working on css". I thought she was a front-end dev. 6 months later I realized she was working literally on the css flexbox spec, not writing css for a site! Glad this flexbox stuff is picking up. people like her put an insane amount of time and effort to make it come out this way.
- kchoudhu 12y agoI went to school with a girl who went by fantasai online and did web-ish stuff -- you wouldn't be talking about someone called Elika, would you?
- grandalf 12y agoProbably is: http://lists.w3.org/Archives/Public/public-css-commits/2011Aug/0105.html http://lists.w3.org/Archives/Public/public-css-commits/2011A...
- kchoudhu 12y agoWell I'll be. Some people have clearly done more with their lives since graduation than others :)
- rburhum 12y agoThat's her :)
- deltaprotocol 12y agoThis is awesome, but the chosen title is misleading. This requires at least 20 minutes.
- mmastrac 12y agoI rebuilt my personal site on Flexbox in December last year after making the call that it was widely supported enough [1]. There were a few hiccups: 1. Safari's requirement to use the webkit- prefix is a pain. Thankfully there are SASS libraries that work around that [2], but you aren't using Flexbox directly. 2. Google's pagespeed tools doesn't support it. It's an ancient version of Webkit -- your mobile score will suffer. If that matters to you, you'll have to do some hacking to ensure that it doesn't affect things on the mobile side. [1] for a personal site. [2] https://github.com/philipwalton/solved-by-flexbox https://github.com/philipwalton/solved-by-flexbox
- bonn1 12y agore 2.: sure? And did you try it with the new Google Mobile Freindly Test too?
- mmastrac 12y agoDefinitely sure. It supported it just marginally enough to mangle it in a way that you couldn't work around. My fix was to literally check if the floating sidebar overlapped the content and, if so, add a css class to the body that I could use to fix the pagespeed insights browser. I'll give the Mobile Friendly Test a shot with and without the hack. Edit: Yup, still busted. And the new test is broken as well (probably using the same backend). This is what it looks like: http://imgur.com/fBIP80y http://imgur.com/fBIP80y
- markdown 12y agoThat's scary, given that in April, Google will start using mobile-readiness in its ranking algo.
- Throwaway90283 12y agoI run a popular site that heavily uses flexboxes, with dozens of flex containers on every page, different alignments, etc. I just checked pagespeed insights, and the site renders fine in the little mobile phone preview from your image, so it's definitely supported. Check your code, it might be incorrect, you might need webkit prefixes, or you might be using outdated flexbox specs that have been dropped.
- untog 12y agoThe first few times I tried to grapple with flexbox I just didn't get it - there were two competing specs, it was messy... now, it's fantastic. I've been using it on mobile projects and it's an absolute godsend to deal with different screen sizes efficiently.
- huskyr 12y agoAnother Flexbox resource that i use almost daily is this one: http://jonibologna.com/flexbox-cheatsheet/ http://jonibologna.com/flexbox-cheatsheet/ Too bad Flexbox doesn't work in IE9 :(
- ryanSrich 12y agoOut of curiosity, are you building a product that needs IE9 support? What industry?
- huskyr 12y agoJournalism. Specifically newspapers. Around 2,3% of our readers still use IE9, which given the number of visitors, is quite a lot.
- Loque 12y agoI can think of lots of products/sites that could benefit from having IE9 support. E-commerce for instance, public services... anything that needs to have a far reach. Still, quite a few options for what you can do without flexbox support ( polyfill / adjust design)
- ClayM 12y agoI know of one specific very large US bank that is still on IE9. I think we go to IE11 this summer? Hopefully?
- brianzelip 12y agoThis is a well executed tutorial. Bug: slide 32/53 reads > [...] and click "resize flexbox". The actual link reads "resize box", not "flexbox" --- I've been thoroughly enjoying working flexbox into frontend design. It really is what we've been missing. Slap autoprefixer into the flow and you have little to worry about if only targeting modern browsers. The single-class oriented css toolkit Basscss.com has a flex-object module [1] that I've been getting miles out of lately. While it doesn't provide single classes for all flexible options, it's a good start and it's easy to add your own styles into the mix. Plus the documentation site itself is a great example of using flex. The Basscss author sort of operationalized Philip Walton's solved by flexbox stuff. [1] http://www.basscss.com/docs/layout/#flex-object http://www.basscss.com/docs/layout/#flex-object
- charleyramm 12y agoMostly broken on Safari
- _devbryce 12y agoSorry about that. When I first built this (many moons ago) it was unreasonably difficult to get it working in Safari. Sounds like it's time to revisit that issue.
- _devbryce 12y agoAuthor/Creator of FlexboxIn5 here: I'm glad to see this thread, because there seem to be some bugs I need to address. Any other features you guys would find helpful? Feel free to tell me here or on twitter: @_devbryce
- PeterWhittaker 12y agoLet people know cookies are required. It took me a moment to realize that's why nothing was happening. Then ask whether you really require cookies. What value do they add?
- PeterWhittaker 12y agoI'm really confused by the downvoting on this site. The page fails to work if cookies are disabled. That is a fact. Some people - a minority, perhaps - disable cookies and other technologies, often for privacy reasons. That is also a fact. (We could discuss the ins and outs of that discussion, the value proposition, the efficacy, etc., but none of those change those two simple facts.) Another fact: Sites that use cookies must announce this use in certain jurisdictions. Again we could discuss the merits of this requirement, but that would not change the fact of it. So were the downvotes for stating facts or for questioning a design decision? I would have thought HN folks were rather keen on both facts and design discussions. Perhaps I'm wrong. I'm definitely surprised. Ah well.
- huckyaus 12y agoStep 32 has me scratching my head. I've set the suggested property values, but all of the elements still shrink at a uniform rate when I click resize box. Am I missing something, or is there an error/omission in the instructions?
- ntucker 12y agoMe too. And on 34, "You'll see that when the item reaches its flex basis, it stops flexing and something else has to flex" doesn't actually seem to be true. Can't tell if there's a bug or if it's something I've done wrong.
- ggvvnn 12y agoFlexbox + Autoprefixer = Win
- domrdy 12y agoI've read that facebook implemented flexbox-like layouting in javascript to use with react native. I wonder how much the two implementations differ. https://www.youtube.com/watch?v=7rDsRXj9-cU&t=996 https://www.youtube.com/watch?v=7rDsRXj9-cU&t=996
- nojvek 12y agoNot much. Facebook used a very thorough testing method where it tests millions of permutations of flexbox variables and compares the output with the browser.
- xiaq 12y agoI find myself very confused after getting to the align-items and align-content part. For those of us who prefer a more formal introduction, the guide on MDN seems pretty well written: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexi...
- serve_yay 12y agoThis seems so well-intentioned! But I think maybe it doesn't always do what it is supposed to do. (It's hard to say -- I'm not quite sure what it is supposed to do!)
- nimbix 12y agoSo how does flexbox compare to the tools we were using in the late 90s/early 00s? Is layout finally as simple again as it was when it was still OK to use tables and a transparent spacer.gif for everything?
- z1mm32m4n 12y agoWhat frameworks are making good strides in adopting flexbox for their grid systems?
- jasongrout 12y agoThis is a nice demo. The blurb about flex-basis should be corrected, though. It says on page 33 that flex-basis basically is a min-width for flex items, but instead flex-basis sets the default (main) size, not the minimum size.
- supercoder 12y agoAn article explaining CSS that seems to have completely broken CSS.
- contradictioned 12y agoIf you made this site: You've got some console.log()s in there :) Anyways so great to see this in action. I mean, one could also try this manually, but this is really nice. PS: http://flexboxin5.com/scss/vendors/_animate.scss http://flexboxin5.com/scss/vendors/_animate.scss Failed to load resource: the server responded with a status of 404 (Not Found) main.js:1117 1