有没有办法重置边框、边框半径和背景颜色的 CSS 属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12964052/
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
Is there a way to reset the border, border-radius, and background-color CSS properties?
提问by Gabriel Petrovay
I am using Twitter bootstrap for the CSS of a page where I have input. Bootstrap defines: border: 1px solid rgb(204, 204, 204); background-color: rgb(255, 255, 255); border-radius: 3px 3px 3px 3px; for select elements.
我正在将 Twitter 引导程序用于我输入的页面的 CSS。Bootstrap 定义:border: 1px solid rgb(204, 204, 204); 背景颜色:rgb(255, 255, 255); 边框半径:3px 3px 3px 3px;用于选择元素。
I want to reset (by overwriting in my own CSS) these Bootstrap CSS property. I tried: auto, inherit, none. But none work. I also tried the -moz prefix for the radius. No success.
我想重置(通过在我自己的 CSS 中覆盖)这些 Bootstrap CSS 属性。我试过:自动,继承,无。但没有工作。我还尝试了半径的 -moz 前缀。没有成功。
I see that this doesn't work because in Firefox, a select that has NO border and NO border-style and NO background-color is rendered in a similar way with the webkit browsers.
我看到这不起作用,因为在 Firefox 中,一个没有边框、没有边框样式和没有背景颜色的选择以与 webkit 浏览器类似的方式呈现。
You can check this by commenting out these rules in the Web Developer -> Inspect -> CSS view.
您可以通过在 Web Developer -> Inspect -> CSS 视图中注释掉这些规则来检查这一点。
How can I do all this without touching the Bootstrap library?
如何在不触及 Bootstrap 库的情况下完成所有这些工作?
采纳答案by bookcasey
The Bootstrap declarations have a higher specificitythan yours.
Bootstrap 声明比您的具有更高的特异性。
You can test this by adding !important
after the declaration: border: none !important
您可以通过!important
在声明后添加来测试:border: none !important
Do not ship with this code, however. To fix it the right way, use another class or id to override Bootstrap's CSS.
但是,不要附带此代码。要以正确的方式修复它,请使用另一个类或 id 来覆盖 Bootstrap 的 CSS。
回答by
-webkit-border-radius: 0;
-moz-border-radius: 0;
-o-border-radius: 0;
border-radius: 0;
border: 0;
That should reset the borders. As long as your preferred styles appear later than the ones provided by Bootstrap, they will take precedence. Also, -moz-appearance may help you override default Firefox appearances (or reset them).
那应该重置边界。只要您喜欢的样式出现在 Bootstrap 提供的样式之后,它们就会优先。此外,-moz-appearance 可以帮助您覆盖默认的 Firefox 外观(或重置它们)。
回答by bookcasey
To reset properties, use value "initial", works on all properties:
要重置属性,请使用值“initial”,适用于所有属性:
-webkit-border-radius: initial;
-moz-border-radius: initial;
-o-border-radius: initial;
border-radius: initial;
border: initial;