分为三种:内部样式、内联样式、外部样式
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>Documenttitle>
head>
<style>
p{
color:red;
text-align: center;
}
style>
<body>
<p>样式p>
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>Documenttitle>
head>
<body>
<p style=" color:blue">样式p>
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>Documenttitle>
head>
<link rel="stylesheet" href="1.css">
<body>
<p>css 样式p>
body>
html>
p{
color: rebeccapurple;
text-align: center;
}

样式应用:

原先:
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>Documenttitle>
head>
<style>
span{
font-size: 2em;
}
style>
<body>
<p>css 样式p>
<span>font-size 文字span>
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>Documenttitle>
head>
<style>
*{
font-size: 10px;
}
span{
font-size: 2em;
}
style>
<body>
<p>css 样式p>
<span>font-size 文字span>
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>Documenttitle>
head>
<style>
ul li{
color: red;
}
.box{
color:blue;
}
#username{
color:yellow;
}
style>
<body>
<ul>
<li>语文li>
<li class="box">英语li>
<li class="box" id="username">数学li>
ul>
body>
html>
- 调用各种类型:
- ul li调用对应的无序标签
- ‘ . ‘调用对应的class
- ’ # ‘调用对应的id
- 标签优先级:id选择器>class选择器>标签选择器

作用:只选择邻近的一个
代码:
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>Documenttitle>
head>
<style>
.box1+.box{
color: red;
}
style>
<body>
<ul>
<li class="box1">语文li>
<li class="box">英语li>
<li class="box" id="username">数学li>
ul>
body>
html>
.box1+.box:
相对于box1的第一个box类型
效果:

作用:选择所有符合条件的
代码:
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>Documenttitle>
head>
<style>
.box1~.box{
color: red;
}
style>
<body>
<ul>
<li class="box1">语文li>
<li class="box">英语li>
<li class="box" id="username">数学li>
ul>
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>Documenttitle>
head>
<style>
div :first-of-type{
color:red;
}
style>
<body>
<div>
<p>数学p>
<p>英语p>
<p>语文p>
<p>物理p>
div>
body>
html>

nth-of-type()注意点
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>Documenttitle>
<style>
p:nth-of-type(3){
color:red;
}
style>
head>
<body>
<div>
<p>数学p>
<p>英语p>
<p>语文p>
<p>物理p>
div>
body>
html>
nth-of-type()前面应该改为p盒子,否则无效







需要使用top、right、left、bottem来进行定位
根据自己的左上角顶点进行定位的
根据父元素左上角的顶点来进行定位的
- 注意:当子元素使用绝对定位时,父元素最好使用相对定位
(因为网页的最顶端还有一个空隙)
代码:
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>Documenttitle>
head>
<style>
.static{
position: static;
width:200px;
height:200px;
border:10px solid #000;
}
.relative{
position: relative;
width:200px;
height:200px;
border:10px solid #000;
}
.absolute{
position: absolute;
width:200px;
height:200px;
border:10px solid #000;
}
.item{
position: absolute;
top:150px;
width:50px;
height:50px;
background-color: blue;
}
style>
<body>
<div class="static">
<div class="item">div>
div>
<div class="relative">
<div class="item">div>
div>
<div class="absolute">
<div class="item">div>
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>my_incofonttitle>
<link rel="stylesheet" href="./iconfont/iconfont.css"/>
head>
<body>
<span class="iconfont icon-huidaodingbu ">span>
body>
html>
效果:
