基本选择器
- 标记选择器:
<style> h1 { /* h1为选择器 */ color: red; /* color为属性,red为属性值*/ font-size: 30px; /* font-size为属性,30px为属性值*/ } </style>
- id选择器: id 选择器以 "#" 来定义
#red {color:red;} -----id选择器只能出现一次,具有唯一性。
- 类选择器:类选择器以一个点 . 号显示
<style> p.center {
text-align:center;
}
</style>
</head>
<body>
<h1 class="center">这个标题不受影响</h1> -------样式前面整体是p.center
<p class="center">这个段落居中对齐。</p>
</body>
<style>
.center {
text-align:center;
}
.color {
color:#ff0000;
}
</style>
</head>
<body>
<h1 class="center">标题居中</h1> --------有样式是center
<p class="center color">段落居中,颜色为红色。</p> --------样式center和color叠加
基本选择器:
关系选择器:
属性选择器:
结构伪类选择器:
伪元素选择器:
当选择器发生冲突时:
内嵌式:
<style>
p{
background-color: pink;
color: white;
text-decoration: underline;
font-weight: bold;
font-size: 35px;
} </style>
</head>
<body>
<p>这是一个实验文件</p>
<p>这是二个实验文件</p>
<p>这是三个实验文件</p>
</body>
链接式(绝对路径,相对路径)?