简体   繁体   English

在不使用!important或内联样式表的情况下覆盖CSS样式行为

[英]Override CSS style behaviour without using !important or inline style sheet

i am facing issue of css override. 我正面临着css覆盖的问题。 below css are applied on textbox(with class xdTextBox ) 下面的css应用于文本框(使用类xdTextBox)

          .xdTextBox   {
            padding:1px;
            line-height:10px; 
            border:2px #cc0 solid;              

} }

     input[type="text"]  {
          padding:10px;
          margin:10px;
          line-height:15px; 
          border:none;

} }

I want Result as textbox with padding:1px, line-height:10px, border:2px #cc0 solid; 我希望结果为带填充的文本框:1px,line-height:10px,border:2px#cc0 solid;

I can't use !important or inline stylesheet 我不能使用!重要或内联样式表

is it possible ? 可能吗 ? please suggest your solution 请建议您的解决方案

Thanks in advance 提前致谢

The general idea of making something more prioritized is to add more specific selectors to it. 制定更优先级的一般想法是为其添加更多特定的选择器。

HTML: HTML:

<input type="text" class="xdTextBox" name="exmapleInput" />

CSS: CSS:

input[type="text"].xdTextBox {
    padding:1px;
    line-height:10px; 
    border:2px #cc0 solid;    
}

For further reading: Reviewing CSS style priority 进一步阅读: 查看CSS样式优先级

A class selector has a lower specifity than a tag and attribute selector - see Calculating a selector's specificity 类选择器的特定性低于标记和属性选择器 - 请参阅计算选择器的特异性

You still have several options to overwrite the browsers default styles - one has @Itay already posted. 您仍然有几个选项可以覆盖浏览器的默认样式 - 其中一个已经发布了@Itay。

As always your selector needs a higher specifity or if it is equal it has to come after in the stylesheet (which automatically is the fact in case of browser default styles). 一如既往,您的选择器需要更高的特定性,或者如果它相等,则必须在样式表中进行(在浏览器默认样式的情况下,这自然是事实)。

And just one word concerning your desired styles: What font-size will you use that you set the line-height to 10px!? 只有一个关于你想要的风格的词:你用什么字体大小设置line-height为10px!? Anyway, always set the font-size and the line-height as an unitless value (multiplyer for the font-size). 无论如何,总是将font-size和line-height设置为无单位值(font-size的乘数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM