不继承怎么办?或者如何将继承的宽度重置为之前的值?(CSS)

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

how to not inherit? or how to reset inherited width to the value before? (css)

cssinheritance

提问by Radek

I installed Thank you pluginbut the button on my test sitelooks strange.

我安装了谢谢插件,但我的测试站点上的按钮看起来很奇怪。

I found out why. Because it inherits #commentform textarea { width: 45%; }from my theme. If I remove the width from css the button looks ok. Any idea how I can fix that? Of course I do not want to remove width for #commentform textarea. Can I do something about that on css level of the button? Something like width:not-inherit; width:reset;I'd say that the width of the button wouldn't be declared at all if there was no #commentform textarea

我发现了原因。因为它继承#commentform textarea { width: 45%; }了我的主题。如果我从 css 中删除宽度,按钮看起来不错。知道我该如何解决吗?当然,我不想删除#commentform textarea 的宽度。我可以在按钮的 css 级别上做些什么吗?就像width:not-inherit; width:reset;我会说的那样,如果没有按钮的宽度,则根本不会声明#commentform textarea

回答by jimr

Try putting

尝试放置

width: auto;

on the button. That should fix it in this case.

在按钮上。在这种情况下应该可以解决它。

回答by andr3wll

It is an old question but I just had the same problem with widthinherit from parent as 100%. Turns out adding displayproperty to inline-blockhelps.

这是一个老问题,但我在width从父级继承 100% 时遇到了同样的问题。原来添加display属性来inline-block帮助。

display: inline-block;

回答by Stéphane

you can add "!important" to the newer css.

您可以将“!重要”添加到较新的 css 中。

ex :

前任 :

first{ float:right;}
second{ float:left !important;}



<div class="first second"></div>

This div should be float left

这个 div 应该向左浮动

回答by Gavrisimo

Put this in your css and also remove that inline styling you have there for that button:

把它放在你的 css 中,并删除那个按钮的内联样式:

input.thanks_button{
    background:url("http://asha.onalllevels.com/wp-content/plugins/thanks-you-counter-button/images/thanks_compact_blue1.png") no-repeat;
    color:#fff;
    font-family:Verdana,Arial,Sans-Serif;
    font-size:14px;
    font-weight:normal;
    width:auto !important;
}