html - How do I make a flexbox switch to column mode when there isn't enough room for row mode? -


i have flexbox this:

three boxes side-by-side

when container narrow, wraps this:

two boxes on first row, , 1 box on second row

but want this:

three boxes stacked vertically

in other words, when flexbox wraps, want wrap everything @ once. it's either horizontal or vertical.

the flexbox elements aren't same size.

can done?

simplest way use media query.

set min-width parent element (or check before hand) , matching media query, change flex-direction column

@media screen , (max-width: 500px) {   .classname {     flex-direction: column;   } } 

side note

if want dig scripting this, eventlistener on resize , load, checking scrollbar this, , have way change style.

so not setting wrap row, @ point create scrollbar, either if page narrow on load or if user resize.

//horizontal scrollbar (function($) {     $.fn.hashorizontalscrollbar = function() {         return this.get(0) ? this.get(0).scrollwidth > this.innerwidth() : false;     } })(jquery);  //vertical scrollbar (function($) {     $.fn.hasverticalscrollbar = function() {         return this.get(0) ? this.get(0).scrollheight > this.innerheight() : false;     } })(jquery);   //use if($("#element").hasverticalscrollbar()){     //do whatever you'd } 

src: https://hasin.me/2013/08/17/detecting-if-a-dom-element-has-scrollbar/


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -