CSS 删除元素的继承属性(框大小)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12863835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:28:47  来源:igfitidea点击:

Removing inherited property of an element (box-sizing)

csstwitter-bootstraplightbox

提问by Gokul Kav

I am using a jQuery light box plugin on a bootstrap site. It has box-sizing: border-boxset via universal selector.

我在引导站点上使用 jQuery 灯箱插件。它已box-sizing: border-box通过通用选择器进行设置。

* {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

The light box div does not appear right because of this (sometimes a vertical scrollbar appears). Once we remove this through web inspector it appears ok. Is there any way to remove the box-sizing property of this particular element. box-sizing:''or box-sizing:nonedoes not appear to work.

因此灯箱 div 显示不正确(有时会出现垂直滚动条)。一旦我们通过网络检查器删除它,它看起来就可以了。有什么方法可以删除此特定元素的 box-sizing 属性。 box-sizing:''box-sizing:none似乎不起作用。

回答by VKen

The box-sizingmsdn, mdnCSS property default is box-sizing: content-box;. Have you tried to use it to override the inherited style?

box-sizingMSDNMDNCSS属性默认为box-sizing: content-box;。您是否尝试过使用它来覆盖继承的样式?

回答by user5371360

you can use

您可以使用

*:not(.classname){
  box-sizing : border-box;
}

classnamewill be the class of element you want to exclude from the universal selector.

classname将是您要从通用选择器中排除的元素类。

回答by Karthik P

I had a similar problem with bootstrap and I did override the box-sizing CSS property for <a>like this,

我在 bootstrap 中遇到了类似的问题,我确实<a>像这样覆盖了 box-sizing CSS 属性,

a *,
a *:before,
a *:after {
    -webkit-box-sizing: content-box !important;
    -moz-box-sizing: content-box !important;
    box-sizing: content-box !important;
}

Customize it for your need.

根据您的需要定制它。

回答by mfralou

Override like this:

像这样覆盖:

* {
box-sizing: border-box!important;
}