1.標(biāo)簽選擇器钳降、類選擇器厚宰、id選擇器、后代選擇器
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
/*標(biāo)簽選擇器*/
div{
color: red;
}
p{
color: blue;
}
/*類選擇器*/
.one{
color: yellow;
}
/*id選擇器*/
#main{
font-size: 40px;
}
/*后代選擇器*/
#test2 div{
color: green;
}
</style>
</head>
<body>
<div id="main">1111111111</div>
<div>1111111111</div>
<div>1111111111</div>
<p>2222222222222</p>
<div class="one">222222</div>
<p class="one">444444444</p>
<div id="test2">
<p>
<div class="test1">
rewgrgrtwgrt
</div>
</p>
</div>
</body>
</html>
2.偽類
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
div{
background-color: red;
width: 200px;
height: 300px;
}
div:hover{
background-color: green;
width: 100px;
height: 180px;
}
input:focus{
outline: none;
width: 500px;
height: 300px;
border: 10px double yellow;
}
</style>
</head>
<body>
<div>11111</div>
<p></p>
<input>
</body>
</html>
3.選擇器的優(yōu)先級(jí)別
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<!--
css選擇器遵循:
1.在相同級(jí)別:1.疊加原則 2.就近原則
2. id選擇器> 類選擇器 > 標(biāo)簽選擇器
3. 范圍越小,優(yōu)先級(jí)別越高
-->
<style>
div#main{ /*101*/
color: goldenrod;
}
/*id選擇器*/
#main{ /*100*/
color: deeppink;
}
/*類選擇器*/
.test2{ /*10*/
color: purple;
}
.test1{ /*10*/
color: yellow;
}
/*標(biāo)簽選擇器*/
div{ /*1*/
color: red;
}
div{ /*1*/
color: green;
}
div{ /*1*/
color: blue;
font-size: 100px;
}
*{ /*1000*/
color: darkgreen !important;
}
</style>
</head>
<body>
<div id="main" class="test1 test2" style="color: red">111111</div>
</body>
</html>
4.html標(biāo)簽的類型
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
/*塊級(jí)標(biāo)簽*/
div{
background-color: red;
width: 200px;
height: 180px;
/*隱藏*/
/*display: none;*/
/*display: inline;*/
display: inline-block;
}
/*p{*/
/*background-color: yellow;*/
/*width: 200px;*/
/*height: 50px;*/
/*}*/
/*行內(nèi)標(biāo)簽*/
span{
background-color: yellow;
/*讓行內(nèi)標(biāo)簽變成塊級(jí)標(biāo)簽*/
/*display: block;*/
/*width: 200px;*/
/*height: 50px;*/
}
/* 行內(nèi)-塊級(jí)標(biāo)簽*/
input{
width: 200px;
height: 300px;
}
</style>
</head>
<body>
<div>11111111</div>
<div>11111111</div>
<div>11111111</div>
<span>22222222</span>
<span>22222222</span>
<span>22222222</span>
<a href="#">百度一下</a>
<a href="#">百度一下</a>
<a href="#">百度一下</a><br><br><br>
<!--<p>22222</p>-->
<input>
<input>
<input>
</body>
</html>
5.css3新增屬性
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
div{
font-size: 30px;
width: 150px;
background-color: red;
margin: 20px;
/*設(shè)置不透明度*/
/*opacity: 0.2;*/
/*box-shadow: 4px 14px 20px black;*/
}
/*設(shè)置透明度:紅色 綠色 藍(lán)色 透明度*/
.test1{
background-color: rgba(255,0,0,1.0);
}
.test2{
background-color: rgba(255,0,0,0.8);
}
.test3{
background-color: rgba(255,0,0,0.6);
}
.test4{
background-color: rgba(255,0,0,0.4);
}
.test5{
background-color: rgba(255,0,0,0.2);
}
p{
font-size: 50px;
color: red;
/*設(shè)置文字陰影, 水平方向 垂直方向 模糊 顏色*/
text-shadow: 5px 5px 10px green;
}
.test6{
background-color: red;
width: 400px;
height: 250px;
border: 20px solid green;
/*設(shè)置圓角*/
/*border-radius: 40px;*/
border-top-left-radius: 90px;
border-bottom-left-radius:100px;
}
</style>
</head>
<body>
<div class="test1">111</div>
<div class="test2">222</div>
<div class="test3">333</div>
<div class="test4">444</div>
<div class="test5">555</div>
<p>小碼哥</p>
<div class="test6">
dewhdewjhdhjew
</div>
</body>
</html>
6.css的常用屬性
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body{
/*設(shè)置字體大小*/
font-size: 30px;
/*設(shè)置文字顏色*/
color: red;
/*字體加粗*/
font-weight: bolder;
}
div{
/*復(fù)合屬性,可用于設(shè)置顏色和圖片*/
background: url("img/7.jpg");
/*設(shè)置背景的尺寸, cover跟隨標(biāo)簽的尺寸顯示*/
background-size: cover;
width: 300px;
height: 300px;
/*水平居中,取值:left right center*/
text-align: center;
/*都是隱藏內(nèi)容,區(qū)別:
1.display會(huì)連同尺寸一起隱藏
2.visibility不會(huì)隱藏尺寸
*/
display: none;
visibility: hidden;
/*設(shè)置光標(biāo)的顯示類型: crosshair pointer*/
cursor: pointer;
}
span{
/*背景顏色*/
background-color: blue;
/*寬度*/
width: 300px;
/*高度*/
height: 200px;
/*行高,用于垂直居中*/
line-height: 300px;
}
a{
/*設(shè)置去除下劃線,用于a標(biāo)簽*/
text-decoration: none;
}
.one{
/*設(shè)置縮進(jìn): % */
text-indent: 3%;
}
ul{
/*設(shè)置列表的類型: none square*/
list-style:square;
}
#main{
/*設(shè)置背景顏色*/
background-color: red;
/*設(shè)置寬度*/
width: 90px;
/*設(shè)置高度*/
height: 120px;
/* 超出標(biāo)簽的內(nèi)容處理:hidden, auto */
overflow: hidden;
}
</style>
</head>
<body>
<!--<div>111111</div>-->
<!--<span>2222222</span>-->
<!--<p>33333333333</p>-->
<div>
<span>12112323322332</span>
</div>
<p class="one">21323243423434efwqewqfewqfewqfewq</p>
<p>21323243423434fewqfewqfew</p>
<p>21323243423434fewfew</p>
<p>fewfewfewfewefw</p>
<a href="#">百度一下</a>
<ul>
<li>111111</li>
<li>111111</li>
<li>111111</li>
<li>111111</li>
</ul>
<div id="main">44444444444444444444</div>
</body>
</html>
7.盒子模型
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
div{
background-color: red;
width: 250px;
height: 250px;
margin: 130px;
/*設(shè)置邊框: 邊框?qū)挾?邊框樣式 邊框顏色*/
border: 10px solid green;
/*內(nèi)邊距: 上右下左*/
padding:20px 40px 100px 20px;
}
</style>
</head>
<body>
<div>122112</div>
</body>
</html>
8.居中
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<!--
標(biāo)簽水平居中:
行內(nèi)標(biāo)簽, 行內(nèi)塊級(jí)標(biāo)簽: text-align: center;
塊級(jí)標(biāo)簽: margin: 0px auto;
標(biāo)簽垂直居中:
line-height: 400px;
-->
<style>
.test1{
background-color: red;
width: 300px;
height: 400px;
text-align: center;
line-height: 400px;
}
span{
background-color: purple;
}
.test2{
background-color: green;
width: 90px;
/*margin-left: auto;*/
/*margin-right: auto;*/
margin: 0px auto;
text-align: center;
}
</style>
</head>
<body>
<div class="test1">
<!--行內(nèi)標(biāo)簽-->
<span>12212</span>
<!--行內(nèi)-塊級(jí)標(biāo)簽-->
<button>百度一下</button>
<!--塊級(jí)標(biāo)簽-->
<div class="test2">efwf</div>
</div>
</body>
</html>