美文网首页
CSS 选择器优先级

CSS 选择器优先级

作者: 欢喜明 | 来源:发表于2018-05-22 15:38 被阅读0次

记录:

在 html 标签中设置 CSS 样式,有四种方法,即 css 选择器有四种:

1、id 选择器(唯一):

<style>

#para1

{

text-align:center;

color:red;

}

</style>

<p id=para1> hello world </p>

2、class 选择器外(多次):

<style>

.para1

{

text-align:center;

color:red;

}

</style>

<p class="para1"> hello world </p>

< p class="para1"> hello world </p>

3、标签选择器,即以 html 标签作为 css 修饰所用的选择器:

<style>

h1{

 color:red;

}

</style>

<h1> hello amei </h1>

PS:所有的<h1>标签都会是红色;

4、直接在标签内部写css代码:

<h3 style="color:red;"> hello </h3>

PS:注意css代码是分号“;”结束的;

优先级:第四种 > id > class > 第三种

相关文章

网友评论

      本文标题:CSS 选择器优先级

      本文链接:https://www.haomeiwen.com/subject/eyahjftx.html