Heim  >  Artikel  >  Web-Frontend  >  CSS中!important的用法和在IE6下的表现_html/css_WEB-ITnose

CSS中!important的用法和在IE6下的表现_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:41:311205Durchsuche

!important的用法和在IE6下的表现:
!important可以提高指定CSS语句的优先级,使用方法是在相应的CSS语句后面加上!important。例如:

<!DOCTYPE html>   <html>   <head>   <meta charset=" utf-8">   <meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title><style type="text/css">.mytest{  color:blue!important;  color:red;}</style></head><body>  <div class="mytest">蚂蚁部落</div></body></html>

大家都知道CSS样式具有“就近原则”,也就是后面定义的样式能够覆盖前面的样式,以上代码中如果不使用!important,那么字体颜色呈现红色。
当前所有的主流浏览器都支持!important,但是IE6上不能完全支持,为什么说是不能够完全支持,因为在有些情况支持,有些情况不支持,例如上面的代码中,IE6浏览器就不支持,文字将以红色字体呈现,再来看下面这么一个例子:

<!DOCTYPE html>   <html>   <head>   <meta charset=" utf-8">   <meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title><style type="text/css">.mytest{  color:blue!important;}.mytest{  color:red;}</style></head><body><div class="mytest">蚂蚁部落</div></body></html>

以上代码中,大家可以看到字体颜色呈蓝色显示,这说明如果两段代码在同一个大括号({})中使用,IE6下就不起做,如果分开在两个大括号({})中使用就会有作用。

原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0501/500.html

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:MUINächster Artikel:在HTML中优雅的生成PDF_html/css_WEB-ITnose