inline-stylesem um documento têm a prioridade mais alta, então, por exemplo, diga se você deseja alterar a cor de um divelemento para blue, mas você tem um inline stylecom uma colorpropriedade definida parared
<div style="font-size: 18px; color: red;">
Hello World, How Can I Change The Color To Blue?
</div>
div {
color: blue;
/* This Won't Work, As Inline Styles Have Color Red And As
Inline Styles Have Highest Priority, We Cannot Over Ride
The Color Using An Element Selector */
}
Então, devo usar jQuery / Javascript? - A resposta é NÃO
Podemos usar o element-attrseletor CSS com !important, observe, !importanté importante aqui, caso contrário, não substituirá os estilos embutidos.
<div style="font-size: 30px; color: red;">
This is a test to see whether the inline styles can be over ridden with CSS?
</div>
div[style] {
font-size: 12px !important;
color: blue !important;
}
Demo
Nota: A utilização !importantsó vai funcionar aqui, mas eu usei
div[style]para selecionar especificamente divtendo style
atributo