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;
}
ดังนั้นฉันควรใช้ jQuery / Javascript หรือไม่? - คำตอบคือไม่ใช่
เราสามารถใช้element-attr
CSS Selector ด้วย!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
แอตทริบิวต์