html样式表的优先级,css样式表important优先级大于内联style设置的样式

今天发现css样式表中使用了important提高优先级后,尽然覆盖了内联样式style中设置的对应样式,老土了。。呵呵

测试代码如下

.c{color:Red !important}

内联style样式无法覆盖样式表中的important,内容显示为红色,而不是内联样式设置的蓝色

提高内联样式style的优先级也需要增加important或者用js设置对象样式增加important属性,这样才能覆盖样式表中的样式

通过css设置

.c{color:Red !important}

内联样式也增加important,这里就显示黑色的了,而不是红色

通过脚本设置,需要注意的是不能直接设置obj.style.color='#000000 !important',而是设置obj.style.cssText='color:#000000 !important'

.c{color:Red !important}

内联样式也增加important,这里就显示黑色的了,而不是红色

window.onload = function () {

//document.getElementsByTagName('div')[0].style.color = '#000000 !important'; //不能这样设置,IE下报错:无效的属性值。

document.getElementsByTagName('div')[0].style.cssText = 'color:#000000 !important';//要这样来设置

}

加支付宝好友偷能量挖...

2013-4-9Web开发网

阅读(4588)喜欢(0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值