简体   繁体   English

如何覆盖内联样式CSS?

[英]How to override Inline Style CSS?

I have tried the div[style] The problem is this is not the only element with inline styles 我已经尝试过div [style]问题是这不是具有内联样式的唯一元素

The HTML HTML

<input class="button cool-button" style="float: right !important color:blue" value="Hello" name="hello">
<input class="button cool-button" style="float: right !important color:blue" value="World" name="hello">
<input class="button cool-button" style="float: right !important  color:blue" value="Submit" name="submit">

I am targeting the submit button 我的目标是提交按钮

This is how I attempted to over-ride the css on my external style sheet... 这就是我试图在外部样式表上改写CSS的方式...

input.button .cool-button[style] [value="Submit"] [name="submit"] {
    float: none !important;
}

if your inputs have the !important syntax in the inline style, than that will take precedence over any css/styles to that element so you wont be able to float:none . 如果您的输入采用内联样式的!important语法,则它将优先于该元素的所有CSS /样式,因此您将无法float:none

<input class="button cool-button" style="float: right !important; color:blue" value="Hello" name="hello">

however, if your inputs do not have !important , you can do the following 但是,如果您的输入没有!important ,则可以执行以下操作

 input.button.cool-button { float: none !important; } 
 <input class="button cool-button" style="float: right ; color:blue" value="Hello" name="hello"> <input class="button cool-button" style="float: right ; color:blue" value="World" name="hello"> <input class="button cool-button" style="float: right ; color:blue" value="Submit" name="submit"> 

and the float:none in the css sheet will override the float: right that is inline 并且css工作表中的float:none将覆盖float: right内联的float: right

It is just one step process that you need to add 这只是您需要添加的一步过程

Element[style].button.cool-button{
float:left !important;
}

For Example based in your case 例如基于您的情况

<input class="button cool-button" style="float: right ; color:blue" value="Hello" name="hello">

Create Custom.css file and add the following line of code 创建Custom.css文件并添加以下代码行

/*To override inline style sheet for 'Input' Element*/

input[style].button.cool-button{
float:left !important;
color:white !important;
}

Hope fully it will help someone! 完全希望它将对某人有所帮助! Thank you Cheers Ishwor Khanal 谢谢干杯伊什沃尔·卡纳尔

Use an extra extension: 使用额外的扩展名:

input.button.cool-button.right{
  float: right;
}

And add the right class instead of the style to the input tags. 并将right类而不是样式添加到输入标签。

However use clear: right to cancel the floating. 但是请使用clear: right取消浮动。

input.button.cool-button { 
    float: none !important; 
}

I hope this helps 我希望这有帮助

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

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