简体   繁体   English

如何使CSS'min-height'属性无效?

[英]How can I make the CSS 'min-height' property ineffective?

Here is my code: 这是我的代码:

 .one, .two { border:1px solid; min-height: 300px; } .two { overflow: auto; } 
 <div class="one">something1</div><br> <div class="two">something2</div> 

All I'm trying to do is deactivate min-height property for .two . 我要做的就是停用.two min-height属性。 I can do the same thing by using auto for height . 我可以通过使用auto for height来做同样的事情。 Like this: .two{height:auto} . 像这样: .two{height:auto} But how can I do that for min-height ? 但是我怎样才能达到min-height呢?

According to the relevant W3.org documentation on the min-height property , the initial value is 0 . 根据有关min-height属性相关W3.org文档 ,初始值为0

Therefore, if you want to override the min-height property on that element and set it back to its initial value, you would use: 因此,如果要覆盖该元素上的min-height属性并将其设置回其初始值,则可以使用:

.two {
  min-height: 0;
}

Of course you could also use the initial value (ie, min-height: initial ), however that isn't supported across all browsers. 当然,您也可以使用initial (即min-height: initial ),但并非所有浏览器都支持。 See this relevant caniuse page for a reference on the current browser support of the initial property. 请参阅此相关的can​​iuse页面 ,以获取有关当前浏览器对initial属性的支持的参考。

set min-height: initial; set min-height: initial; that would let you to min-height: 0 那会让你达到min-height: 0

 .one, .two { border: 1px solid; min-height: 300px; } .two { overflow: auto; min-height: initial; } 
 <div class="one">something1</div> <br> <div class="two">something2</div> 

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

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