In flexbox, why do we define the container and not the elements themselves?

Viewed 197

I'm trying to understand the flex property.

Why do we apply float and display: inline-block to the elements that are nested inside a container, while with display: flex, we define the container itself? How can the elements inside be display:block and still be positioned on the same row?

.flex {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  flex-direction: row;
}

@media (max-width: 600px) {
  .flex {
    flex-direction: column;
  }
}

#aaa {
  border: 3px solid black;
  flex: 2;
}

#aa {
  border: 3px solid black;
  flex: 1;
}

#a {
  border: 3px solid black;
  flex: 1;
}

#bbb {
  width: 300px;
}

#ccc {
  float: left;
  border: 5px solid yellow;
  width: 200px;
}

#ddd {
  clear: both;
}

.one {
  background: red;
  height: 50px
}

.two {
  background: green;
  height: 50px
}

.tree {
  background: blue;
  height: 50px
}

#eee {
  display: inline-block;
  width: 200px;
}
<div class=flex>
  <div id=a class="one">flex</div>
  <div id=aa class="two">flex</div>
  <div id=aaa class="tree">flex</div>
</div>
<div class=block>
  <div id=bbb class="one">block</div>
  <div id=bbb class="two">block</div>
  <div id=bbb class="tree">block</div>
</div>
<div class=float>
  <div id=ccc class="one">float</div>
  <div id=ccc class="two">float</div>
  <div id=ccc class="tree">float</div>
</div>
<div class=block>
  <div id=ddd class="one">block</div>
  <div id=ddd class="two">block</div>
  <div id=ddd class="tree">block</div>
</div>
<div class=block>
  <div id=eee class="one">block</div>
  <div id=eee class="two">block</div>
  <div id=eee class="tree">block</div>
</div>

CodePen demo

1 Answers
Related