CSS引入方式
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS三种引入方式</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--外部样式-->
<link type="text/css" rel="stylesheet" href="style.css" />
<!--内嵌样式-->
<style>
.head{
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<!--行内样式-->
<p style="color:#F00; "></p>
<div class="head"></div>
<div></div>
</body>
</html>
选择器
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>选择器</title>
<style>
p{color: darkmagenta;}
.header{
width: 1920px;
}
#main{
width: 1920px;
}
/* 同级相邻选择器 */
.str+li{color: deepskyblue;}
/* 同级所有选择器 */
.int~li{color: gold;}
/* 后代选择器 */
ul li{
color: hotpink;
}
/* 子元素选择器 */
body>ul>li{
color: rgb(228, 51, 20);
}
</style>
</head>
<body>
<p>标签选择器</p>
<div class="header">class选择器</div>
<div id="main"></div>
<ul>
<li>text1</li>
<li class="str">text2</li>
<li>text3</li>
<ul>
<li class="int">text4</li>
<li>text5</li>
<li>text6</li>
</ul>
</ul>
</body>
</html>
伪类选择器
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>伪类选择器</title>
<style>
ul li:nth-of-type(3){
color: hotpink;
}
ul li:nth-of-type(n){
color: hotpink;
}
ul li:nth-of-type(2n){
color: #000;
}
ul li:nth-of-type(2n+1){
color: lawngreen;
}
ul li:nth-of-type(even){
color: lightcoral;
}
ul li:nth-of-type(odd){
color: lightgray;
}
ul li:first-of-type{color: mediumvioletred;}
ul li:last-of-type{color: midnightblue;}
ul li:nth-of-type(n+5){color: blue;}
ul li:nth-last-of-type(-n+3){color: brown;}
ul li:nth-last-of-type(4){color: rgb(243, 16, 84);}
ul li:only-of-type{color: darkblue;}
</style>
</head>
<body>
<ul>
<li>text1</li>
<li>text2</li>
<li>text3</li>
<li>text4</li>
<li>text5</li>
<li>text6</li>
<li>text7</li>
<li>text8</li>
<li>text9</li>
</ul>
<ul>
<li>texts</li>
</ul>
</body>
</html>