CSS 如何覆盖边框:无?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9039577/
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-30 02:46:06  来源:igfitidea点击:

How to override border:none?

css

提问by Shpigford

I'm working with some thoroughly awful third-party software and needing to overwrite their CSS styling via an external CSS file.

我正在使用一些非常糟糕的第三方软件,需要通过外部 CSS 文件覆盖它们的 CSS 样式。

They've set border: noneon all form fields, but I'd like to have the input fields just use the browser's default styling.

他们已经设置border: none了所有表单字段,但我希望输入字段只使用浏览器的默认样式。

How can I override the border: noneso that the form fields are styled as if no borderproperty was set?

如何覆盖border: none以便表单字段的样式设置为好像没有border设置属性?

回答by Caleb Hearth

Style the exceptions as border: inherit.

将异常样式设置为border: inherit.

This will override the most recent border rule.

这将覆盖最近的边界规则。

回答by stelar7

You could try setting the value to nothing, if that desnt work, you could try this: how to remove css property using javascript?

您可以尝试将值设置为空,如果 desnt 工作,您可以尝试以下操作: 如何使用 javascript 删除 css 属性?

回答by j08691

Assuming they aren't styling the input fields inline:

假设他们没有内联输入字段的样式:

input {
    border: 1px solid #999 !important;
}

回答by Jukka K. Korpela

Unfortunately, there is no way in CSS to say that browser defaults be applied. For example, if any CSS rule sets a border on an element, then you can't say “ignore that rule”; you can only set your own rule that overrides it (if you define your rule so that it wins in the cascade).

不幸的是,在 CSS 中没有办法说应用浏览器默认值。例如,如果任何 CSS 规则在元素上设置了边框,那么您不能说“忽略该规则”;您只能设置自己的规则来覆盖它(如果您定义了规则,使其在级联中获胜)。

In practice, the following creates a border that is close to the defaults of popular browsers:

在实践中,下面创建了一个接近流行浏览器默认值的边框:

input { border: solid 1px #ddd; border-top-color: #aaa; padding: 2px; }

You may need to modify the selector (or even use !important) in order to win a setting in another stylesheet.

您可能需要修改选择器(甚至使用!important)才能赢得另一个样式表中的设置。