css:如何用更大(限制较少)的值覆盖最大宽度值

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

css: how to override max-width value with a larger (less restrictive) value

overridingcss

提问by moondog

I have a css file with this style:

我有一个这种样式的 css 文件:

.filefield-element .widget-edit {max-width: 70%;}

I wanted to increase the max-width without modifying that css file, so I created a custom css file with this style:

我想在不修改该 css 文件的情况下增加最大宽度,因此我创建了一个具有以下样式的自定义 css 文件:

.filefield-element .widget-edit {max-width: 99%;}

In the "html/styles" pane, I see that the styles are listed in the correct order:

在“html/styles”窗格中,我看到样式按正确的顺序列出:

.filefield-element .widget-edit {
    max-width: 99%;
}

.filefield-element .widget-edit {
    float: left;
    max-width: 70%;
}

However, "max-width: 99%" is not overriding "max-width: 70%". It seems that the more restrictive value (70%) is used, even when the less-restrictive value (99%) comes first.

但是,“max-width: 99%”不会覆盖“max-width: 70%”。似乎使用了限制性更强的值 (70%),即使是限制性较低的值 (99%) 首先出现时也是如此。

Is there a way to override a max-width value with a larger (less restrictive) value?

有没有办法用更大(限制较少)的值覆盖最大宽度值?

回答by Jim Morrison

You can override (unset) max-width with

您可以覆盖(取消设置)最大宽度

.foo{ max-width:none; }

... to clear any inherited max-width.

...清除任何继承的最大宽度。

回答by duri

Try using !important, or selectorwith higherspecificity.

尝试使用!important, 或具有更高特异性的选择器

回答by pmko

Use JavaScriptto set max-widthto nonefirst, then reassign a new value.

首先使用JavaScript设置max-widthnone,然后重新分配一个新值。

回答by Scott Brown

This is a specificity issue. Take a look at http://htmldog.com/guides/cssadvanced/specificity/.

这是一个特殊性问题。看看http://htmldog.com/guides/cssadvanced/specificity/

Basically, you need to make one more specific than the other. Put the containing element before .filefield-element .widget-editand it will be overridden

基本上,您需要使一个比另一个更具体。将包含元素放在前面.filefield-element .widget-edit,它将被覆盖