Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS height 100% in firefox not working

Tags:

html

css

I have the following HTML and CSS that behaves totally different in Firefox and Chrome.

JSFiddle.

.container {
  width: 200px;
  height: 50px;
  border: 1px solid black;
  display: inline-table;
}

.content {
  background-color: red;
  width: 30%;
  height: 100%;
}
<div class="container">
    <div class="content"></div>
</div>
<div class="container">
    <div class="content"></div>
</div>

In Chrome it displays correctly but not in Firefox.

Chrome:
enter image description here

Firefox:
enter image description here

By inspecting the content div in Firefox, the height is 0.

Why does it work in Chrome and Safari, but not in Firefox? I notice that removing the display: inline-table will work but the container div will be stacked instead of inline.

like image 854
pdiddy Avatar asked Jan 06 '14 18:01

pdiddy


People also ask

How do I change my height to 100% in CSS?

height:100vh box class has only 100vh which is 100% of the viewport height. When you set the height to 100vh, the box element will stretch its height to the full height of the viewport regardless of its parent height.

What does HTML height 100% mean?

For years, the answer was the following: html { height: 100%; } body { min-height: 100%; } This allows the HTML element to reference the parent viewport and have a height value equal to 100% of the viewport value.


2 Answers

Try changing display: inline-table; to display: inline-block;.

like image 191
kmoe Avatar answered Oct 24 '22 06:10

kmoe


http://jsfiddle.net/yAa3y/12/

I could only get it to work when I used

.content {
    display: inline-table;
 }
like image 44
CRABOLO Avatar answered Oct 24 '22 06:10

CRABOLO