标签、类、ID选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
/* 标签选择器 */
h3{
color: blue;
}
/* class类选择器可以应用多个语句 */
.red{
color: red;
}
/* ID选择器只能应用一个语句 */
#sp{
color: springgreen;
}
</style>
<body>
<!-- 标签选择器调用 -->
<h3>hello</h3>
<!-- 类选择器调用 -->
<span class="red">你好么</span>
<h3 class="red">你好么</h3>
<!-- ID选择器调用 -->
<span id="sp">word</span>
</body>
</html>
后代选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 后代选择器 */
div span{
color: tomato;
}
</style>
</head>
<body>
<!-- + 代表兄弟元素 比如:h2+span -->
<div>
<h2>我喜欢的:</h2>
<span>西瓜</span>
<span>龙眼</span>
<span>橙子</span>
</div>
<h2>我不喜欢的:</h2>
<span>榴莲</span>
<span>臭豆腐</span>
</body>
</html>
子代选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 子代选择器 */
.fount>span{
color: tomato;
}
</style>
</head>
<body>
<!-- + 代表兄弟元素 比如:h2+span -->
<div class="fount">
<h2>我喜欢的:</h2>
<span>西瓜</span>
<span>龙眼</span>
<span>橙子</span>
<!-- div的孙子辈 -->
<p>
<span>其实最喜欢香蕉</span>
</p>
</div>
<h2>我不喜欢的:</h2>
<span>榴莲</span>
<span>臭豆腐</span>
</body>
</html>
交集选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 交集选择器 */
span.red{
color: red;
}
</style>
</head>
<body>
<!-- span.red 定义span里面的class为red span#red 定义span里面的ID为red -->
<span class="red">hongse</span>
<span class="red">hongse</span>
<span class="red">hongse</span>
<div class="red">hongse</div>
<div class="red">hongse</div>
<div class="red">hongse</div>
</body>
</html>
并集选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 并集选择器用,连接元素 */
div,span,p{
color: green ;
}
</style>
</head>
<body>
<div>绿色</div>
<span>绿色</span>
<p>绿色</p>
</body>
</html>
连接伪类选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/*
1. 连接没有被访问过 link
2. 连接被访问过 visited
3. 鼠标移动到连接上 hover
4. 鼠标按下不松开 active
*/
a:link{
color: blue;
}
a:visited{
color: blue;
}
a:hover{
color: blueviolet;
}
a:active{
color: black;
}
</style>
</head>
<body>
<a href="http://www.baidu.com">百度一下</a>
</body>
</html>