Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

height 100% doesn't work, two divs inside div

Tags:

html

css

See css: http://jsfiddle.net/4JgA4/114/

Also here:

<div style="min-height:40px; border:solid 1px black; float:left;">
      <div style="border:solid 1px black; height:150px; float:left;">
       First to set height
      </div>

       <div style="border:solid 1px red; height:100%; float:left;">
      Why don't get the 100%
    </div>
</div>

Why does the second div doesn't get the 100%?

like image 583
Michael Blok Avatar asked May 26 '26 15:05

Michael Blok


2 Answers

<div style="min-height:40px; height:150px; border:solid 1px black; float:left;">
    <div style="border:solid 1px black; height:100%; float:left;">
    Your text 1
    </div>

    <div style="border:solid 1px red; height:100%; float:left;">
    Your text 2
    </div>
</div>
  • The reason is you didn't put exact height (150px) for the first .
  • One more thing, you have already put exact height for th first height, you only need to height = 100% for inside tags.

Here is the result: http://jsfiddle.net/4JgA4/117/

like image 164
Ni Ngo Avatar answered May 28 '26 04:05

Ni Ngo


It doesn't get the full height because the original container has no height. So 100% of nothing is still nothing.

If you give the parent div a height, then the 100% will take effect.

As seen here: http://jsfiddle.net/4JgA4/115/

<div style="min-height:40px; border:solid 1px black; float:left; height:150px;">
    <div style="border:solid 1px black; height:150px;  float:left;">
    First to set height
    </div>

    <div style="border:solid 1px red; height:100%; float:left;">
    Why don't get the 100%
    </div>
</div>
like image 41
Kyle Muir Avatar answered May 28 '26 06:05

Kyle Muir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!