如何使用外部CSS覆蓋內聯樣式?我有使用內聯樣式的標記,但是我沒有權限更改這個標記。如何僅使用CSS覆蓋文檔中的內聯樣式?我不想使用jQuery或JavaScript。HTML:<div style="font-size: 18px; color: red;">
Hello World, How Can I Change The Color To Blue?</div>CSS:div {
color: blue;
/* This Isn't Working */}
3 回答
慕俠2389804
TA貢獻1719條經驗 獲得超6個贊
inline-stylesdivblueinline stylecolorred
<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 */}element-attr!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只會在這里工作,但我用過 div[style]選擇器專門選擇 div有 style屬性
鳳凰求蠱
TA貢獻1825條經驗 獲得超4個贊
!important
<div style="font-size: 18px; color: red;">
Hello World, How Can I Change The Color To Blue?</div>div {
color: blue !important;
/* This will Work */
}<div style="font-size: 18px; color: red !important;">
Hello World, How Can I Change The Color To Blue?</div>div {
color: blue !important;
/* This Isn't Working */
}red
- 3 回答
- 0 關注
- 1958 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消
