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

Flex display items 3X3 row top, center, bottom

I am trying to create a flex-box container following display:
enter image description here

I was able to do:

.garden {
  width: 500px;
  height: 500px;
  background: #CCC;
}
.flower {
  border: 1px solid #000;
  width: 100px;
  height: 100px;
}
.row {
  display: flex;
}
.row:first-child {
  justify-content: space-between;
}
.row:nth-child(2){
  justify-content: center;
}
.row:last-child {
  justify-content: space-around;
}
<div class="garden">
  <div class="row">
    <div class="flower red">Red</div>
    <div class="flower green">Green</div>
    <div class="flower yellow">Yellow</div>
  </div>
  <div class="row">
    <div class="flower red">Red</div>
    <div class="flower green">Green</div>
    <div class="flower yellow">Yellow</div>
  </div>
  <div class="row">
    <div class="flower red">Red</div>
    <div class="flower green">Green</div>
    <div class="flower yellow">Yellow</div>
  </div>
</div>

How should I align first row to the top, 2nd row to middle center and last row to bottom?

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 :

You could set also the .garden element as a flexbox container, with column direction and proper spacing:

.garden {
  width: 500px;
  height: 500px;
  background: #CCC;
  display: flex;
  flex-direction: column;
  justify-content: space-between
}
.flower {
  border: 1px solid #000;
  width: 100px;
  height: 100px;
}
.row {
  display: flex;
}
.row:first-child {
  justify-content: space-between;
}
.row:nth-child(2){
  justify-content: center;
}
.row:last-child {
  justify-content: space-around;
}
<div class="garden">
  <div class="row">
    <div class="flower red">Red</div>
    <div class="flower green">Green</div>
    <div class="flower yellow">Yellow</div>
  </div>
  <div class="row">
    <div class="flower red">Red</div>
    <div class="flower green">Green</div>
    <div class="flower yellow">Yellow</div>
  </div>
  <div class="row">
    <div class="flower red">Red</div>
    <div class="flower green">Green</div>
    <div class="flower yellow">Yellow</div>
  </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