继承
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=<!>, initial-scale=1.0">
<title>Document</title>
</head>
<style>
body{
font-size:12px;
}
p{
color: red;
background-color: turquoise;
}
p>span{
background-color: violet;
}
div{
color: turquoise;
}
</style>
<body>
<!--p元素里面可以放行内元素,但是不能放块元素-->
<p>
我是一个p元素
<br>
<span>
我是p中的span元素
</span>
</p>
<span>我是p元素外的span</span>
<div>
我是div
<span>
我是div中的span
<em>我是span中的em</em>
</span>
</div>
</body>
</html>
选择器的权重
<!DOCTYPE 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>Document</title>
</head>
<style>
div{
color: cornflowerblue;
}
.red{
color: crimson;
}
#box{
color:chocolate;
}
div#box{
color: darkmagenta;
}
*{
font-size: 50px;
}
div{
font-size: 20px;
}
</style>
<body>
<div id="box" class="red" style="color: teal;">我是一个div <span>我是div中继承的span</span></div>
<!-- 内联样式选择器,级别最高 <div id="box" class="red" style="color: chartreuse;"><span>我是div中继承的span</span></div>-->
</body>
</html>
像素 百分比 em rem
<!DOCTYPE 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>Document</title>
</head>
<style>
html{
font-size: 16px;
}
.box1{
width:200px;
height:100px;
background-color: teal;
}
.box2{
width: 50%;
height: 50%;
background-color: yellow;
}
.box3{
font-size: 16px;
width: 10em;
height: 10em;
background-color: greenyellow;
}
</style>
<body>
<div class="box1">
<div class="box2"></div>
</div>
<div class="box3"></div>
</body>
</html>
颜色 RGB HSL
<!DOCTYPE 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>Document</title>
</head>
<style>
.box1 {
width: 100px;
height: 100px;
background-color: rgb(255, 255, 255);
background-color: rgb(255, 255, 255, .5);
background-color: #bfa;
background-color: #ff0;
background-color: rgb(255, 255, 255);
background-color: hsl(0, 100%, 50%);
}
</style>
<body>
<div class="box1"></div>
</body>
</html>