0

Let's say I have a container div with 2 elements

<div class="container" >  

  <div class="section" ></div>
  <div class="text" >Some text</div>

</div>

My question is, how can I write the CSS so that the height of the .text div, containing all the text is as big as the .section div, so for example if

.section{
  height: 450px;
}

Then height for .text is also 450px. Or do I need javascript to do this

Ryu
  • 31
  • 2

2 Answers2

0

You can give them both the same percentage height and then set the height based on the parent

.section {
  height: 50%;
  background: red;
}

.text {
  background: green;
  height:50%;
}

.container{
height:450px}
<div class="container">

  <div class="section"></div>
  <div class="text">Some text</div>

</div>
aprouja1
  • 1,800
  • 8
  • 17
  • In my particular example, the parent or both the children don't have a set height. The height of the .section element is decided by how many images are rendered inside (let's say the user decides that). Height of .container is decided by it's children (so .section) and then .text should be the same size as .section – Ryu May 18 '20 at 14:30
-2

You should put text div inside section div so it affect changes, like this:

 <div class="section" >
      <div class="text" >Some text</div>
    </div>

.section {
  height: 450px;
  background: red;
}
sosaN
  • 9
  • 3