What is the classical way to use nested flex boxes?

Viewed 52

How to freely use flex content inside flex content? I'm trying to make the entire display of a website using flex boxes and I'm stuck in the nav part. I want to put a logo on the left and the subscription bottom on the other side.

In my example below, I'm trying to write the number 1 on the left and 3 on the extreme right. How can I achieve it?

.container {
  font-size: 300px;
  display: flex;
  flex-direction: column;
}

.box1 {
  background-color: blue;
  display: flex;
  justify-content: space-between;
}

.box2 {
  background-color: pink
}
<div class="container">
  <div class="box1">1 3</div>
  <div class="box2">2</div>
</div>

1 Answers

Flex will work on child elements and not on text inside the parent element, but in your html code box1 had no child elements. it means no flex items. But after putting 1 and 3 inside separate div it works fine as it should.

.container {
  font-size: 150px;
  display: flex;
  flex-direction: column;
}

.box1 {
  background-color: blue;
  display: flex;
  justify-content: space-between;
}

.box2 {
  background-color: pink;
  display:flex; 
  justify-content: space-between;
 
}

img {
  height: 200px;
  width: 200px;
}
<div class="container">
  <div class="box1">
    <div>1</div>
    <div>3</div>
  </div>
  <div class="box2">
    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTrS4liFW97y5A-3TWyNQ-6cEAJwcDtUBUr2eAw-z41YDsEhewI0WQlBRYI05te-e4IB_M&usqp=CAU">
    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTrS4liFW97y5A-3TWyNQ-6cEAJwcDtUBUr2eAw-z41YDsEhewI0WQlBRYI05te-e4IB_M&usqp=CAU">
  </div>
</div>

Related