inline-stylesドキュメント内の優先度が最も高いので、たとえば、div要素の色をに変更したいが、プロパティをに設定しblueたinline styleとしcolorますred
<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 */
}
それで、jQuery / Javascriptを使用する必要がありますか?-答えはNOです
ここでは、element-attrCSSセレクターを使用できます!important。これ!importantは重要です。そうしないと、インラインスタイルを上書きしません。
<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;
}
デモ
注:!importantここではONLYを使用div[style]できますdivが、セレクターを使用
して特定のstyle
属性を選択しています