minheight能继承吗_从具有min-height属性的父级继承的子div的高度

I'm sorry if this is an old issue or a known problem, but I haven't been able to find an answer online. If I have the code

html, body { height: 100%; width: 100%;}

#div1 {height:50%; min-height:200px;background-color:red;}

#div2 {height:100%; background-color:black;}

Then in firefox the black inner div shrinks as the screen shrinks and stops at 200px height. However in a webkit browser the red outer div stops but the inner div continue to shrink as if it was in a parent div without the min-height attribute.

Is there an easy fix to bring the webkit version into line with the firefox rendering? A min-height:inherit works if placed on the inner div, but in the case of many divs within one this would require min-height:inherit on each child div. Are there any more elegant solutions?

解决方案

Yes, this is a WebKit bug, bug 26559.

height in % on static-or-relative-positioned elements is calculated relative to the containing block's stated height property, instead of the calculated height taking min-height and max-height into account. The same does not occur for width.

You can sort of see where this comes from in CSS 2.1 which states that the height of a containing block must be explicitly set in order for % to work. But it's not explicitly stated what ‘explicitly’ means! Browsers have taken this to mean that the height property must be set to a non-auto value, which is fair enough except that height isn't all there is to height now. Other browsers allow min-height/max-height to affect the height to be used, but don't allow it to mean ‘explicit’. WebKit goes farther (and this definitely isn't mandated by spec) by using only height in the calcation and not min/max.

As a workaround, you could try absolute positioning, which isn't affected. Relative-position the outer div, absolute-position the inner at left: 0; top: 0; width: 100%; height: 100%.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值