简体   繁体   English

Firefox的CSS高度100%无法正常工作

[英]CSS height 100% in firefox not working

I have the following HTML and CSS that behaves totally different in Firefox and Chrome. 我有以下HTML和CSS在Firefox和Chrome中表现完全不同。

JSFiddle . 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中,它可以正确显示,但不能在Firefox中显示

Chrome: 铬:
在此输入图像描述

Firefox: 火狐:
在此输入图像描述

By inspecting the content div in Firefox, the height is 0. 通过检查Firefox中的内容div,高度为0。

Why does it work in Chrome and Safari, but not in Firefox? 为什么它适用于Chrome和Safari,但不适用于Firefox? I notice that removing the display: inline-table will work but the container div will be stacked instead of inline. 我注意到删除display: inline-table将起作用,但容器div将被堆叠而不是内联。

Try changing display: inline-table; 尝试更改display: inline-table; to display: inline-block; display: inline-block; .

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

I could only get it to work when I used 我用它时才能让它工作

.content {
    display: inline-table;
 }

The element does not display properly because FireFox is locking it to the size of the inner content, but I'm sure you already gathered that. 该元素无法正常显示,因为FireFox将其锁定为内部内容的大小,但我相信您已经收集了该内容。

I noticed that the container height that holds the inner is fixed to 50. If you have a fixed height for the outer container, you could match the height for the inner element. 我注意到固定内部的容器高度固定为50.如果外部容器的高度固定,则可以匹配内部元素的高度。

I know this isn't the dynamic solution based on percent, but it's a work around. 我知道这不是基于百分比的动态解决方案,但它是一个解决方案。

try this its working 尝试这个工作

position: absolute; 
top: 0px;
bottom: 0px;
width: 50px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM