Modern Solutions to Old CSS Problems (Part 2): Equal Height Elements: Flexbox vs Grid

Greetings. I present to your attention the translation of the article β€œEqual Height Elements: Flexbox vs. Grid ” , published on April 9, 2020 by Stephanie Eckles





This is the second article in a series that explores the modern ways of solving CSS problems I've encountered in my over 13 years as a front-end developer.



( 7 ) JQuery-, , . , , . float, , .



Flexbox



Flexbox :



.flexbox {
  display: flex;
}


! .





, .column, .





, 100%



.flexbox {
  display: flex;
}

/* ,          */
.element {
    height: 100%;
}


.element.



Grid



Grid, :



.grid {
  display: grid;
  /*      */
  grid-auto-flow: column;
}


Flexbox, , , Flexbox:



.flexbox {
  display: grid;
  grid-auto-flow: column;
}

/* ,         */
.element {
    height: 100%;
}


Codepen- :





?



, Flexbox , , Grid . , ( , , ).



Grid , , . , , "". Grid- , Flexbox .



Grid 3 .column :



&.col-3 {
  grid-gap: $col_gap;
  grid-template-columns: repeat(3, 1fr);
}


, Flexbox :



$col_gap: 1rem;

.flexbox.col-3 {
  /*           */
  flex-wrap: wrap;

  .column {
    /*   "gap" */
    margin: $col_gap/2;
    /*   
    max-width: calc((100% / 3) - #{$col_gap});
  }
}


, ,




All Articles