Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get my flex layout to stack for mobile?

I want to have the second column drop down below the first column when I resize the page to smart phone size.

Thank you for your help!

.row {
  display: flex;
  /* equal height of the children */
}

.col {
  flex: 1;
  /* additionally, equal width */
  padding: 1em;
  border: solid;
}

@media screen and (min-width:760px) {
  .row {
display: column;

  }
<div class="row">
  <div class="col">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
  <div class="col">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad omnis quae expedita ipsum nobis praesentium velit animi minus amet perspiciatis laboriosam similique debitis iste ratione nemo ea at corporis aliquam.</div>
</div>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I did a few things here.

  • Set the initial flex direction to column. Working "mobile first" is a good strategy.
  • Set the flex direction to row at your breakpoint.
  • Fixed the syntax of your media query.
  • Renamed your classes to be more semantically correct. (A row isn’t a row if it’s a column.)
.flex-outer {
  display: flex;
  flex-direction: column;
}

.flex-inner {
  flex: 1;
  padding: 1em;
  border: solid;
}

@media (min-width: 700px) {
  .flex-outer {
    flex-direction: row;
  }
}
<div class="flex-outer">
  <div class="flex-inner">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
  <div class="flex-inner">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad omnis quae expedita ipsum nobis praesentium velit animi minus amet perspiciatis laboriosam similique debitis iste ratione nemo ea at corporis aliquam.</div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading