CSS的基本介绍
![](https://img-blog.csdnimg.cn/img_convert/847c6771b0a1058e2bcc4817027f6d83.png)
![](https://img-blog.csdnimg.cn/img_convert/0efa9b4c9382bd26a798dbd2edea76e6.png)
CSS基本内容
![](https://img-blog.csdnimg.cn/img_convert/9d562e4a84ee6e3cdb66be1105a645b2.png)
![](https://img-blog.csdnimg.cn/img_convert/0728272b29ad32200601d85ce1d79782.png)
CSS的文件结构
![](https://img-blog.csdnimg.cn/img_convert/d0b07008ce9492a2201106a3c550801a.png)
凡是html中的标签都可以进行选中,p代表标签中所有的p标签都遵从以上格式。
![](https://img-blog.csdnimg.cn/img_convert/c22c75831943a6161782e85ef68e99e6.png)
CSS选择器
![](https://img-blog.csdnimg.cn/img_convert/6986f70e02a25b9bd05f0c8ac4317a77.png)
![](https://img-blog.csdnimg.cn/img_convert/f87204eb23be4fa9ad52f3acc2f08ffb.png)
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
p{
background-color: red;
font-size: 40px;
}
.p1{
font-family:楷体;
}
</style>
<title>Document</title>
</head>
<body>
<p>wwww.imooc.com</p>
<p class="p1">慕课网</p>
<p class="p1">层叠了P效果和P1效果双重效果</p>
</body>
</html>
内部样式常见属性
![](https://img-blog.csdnimg.cn/img_convert/9291010261748d9d51b589e37caad67d.png)
![](https://img-blog.csdnimg.cn/img_convert/d5548f2056adbd8aba98aa6409782e1e.png)
外部样式的使用
![](https://img-blog.csdnimg.cn/img_convert/0ae16c5d37f324145b46c70f0c54fd77.png)
![](https://img-blog.csdnimg.cn/img_convert/181020fb76bee3009fcfdbec144cc38a.png)
![](https://img-blog.csdnimg.cn/img_convert/85a2fc97d25a1ebc03a53c97b67e78ba.png)
![](https://img-blog.csdnimg.cn/img_convert/c0a67e4a09aa85e4fd358b7eb13130b5.png)
样式引用的优先级
![](https://img-blog.csdnimg.cn/img_convert/75a26a451618ee5c099a7ca9fb997b5c.png)
文本样式常见的属性
![](https://img-blog.csdnimg.cn/img_convert/239d3f826eb2d8605d8644f975ed4fd4.png)
三种颜色表示方法:英文,16进制表示方法,RGB表示方法。
![](https://img-blog.csdnimg.cn/img_convert/5682946e15b76187382dbba3c6b5ae3d.png)
![](https://img-blog.csdnimg.cn/img_convert/c3f2786b1f2cbdafc8ca10cb34642b53.png)
字体类样式常见属性
![](https://img-blog.csdnimg.cn/img_convert/5a55e38668723f61a58cb52c67368042.png)
![](https://img-blog.csdnimg.cn/img_convert/6a5b943d46120e591b78b8ad5918e7c9.png)
![](https://img-blog.csdnimg.cn/img_convert/978471c098e4b6df0b5271e896e5133e.png)
![](https://img-blog.csdnimg.cn/img_convert/c1300e94b3c603c84832e484b410b07e.png)
![](https://img-blog.csdnimg.cn/img_convert/afbfc08612010c481f1f991b505a9421.png)
![](https://img-blog.csdnimg.cn/img_convert/ef8f8eb3924a592611a10c8f92b1af13.png)
伪类样式
![](https://img-blog.csdnimg.cn/img_convert/5e56d7fc339ab61f119ad211ed02aeed.png)
伪类就是一种特殊的类的形式,专门用于设置超链接点击前后等的样式状态。
点击前是红色 点击后是绿色 悬停是黄色30Px
![](https://img-blog.csdnimg.cn/img_convert/03176a2a3569d1fb32df2a3e0d89cc85.png)
![](https://img-blog.csdnimg.cn/img_convert/a6f2368fa7e9ae5620a0fdccf0fbfaa8.png)
![](https://img-blog.csdnimg.cn/img_convert/55dc4d6089e2488bfa046b3e50538a91.png)
当然其他标签也可以设置
![](https://img-blog.csdnimg.cn/img_convert/d22b219e65f5c7fba45dbf2dee6a5030.png)
![](https://img-blog.csdnimg.cn/img_convert/a4dc2c2c7c6033c1fbe6bd5b59a7d1e5.png)
![](https://img-blog.csdnimg.cn/img_convert/ee418e01f9148b79e06ec9ceb053a27f.png)
![](https://img-blog.csdnimg.cn/img_convert/3bb4de0bf97ac7d6c694fa82f293223a.png)
伪元素选择器
![](https://img-blog.csdnimg.cn/img_convert/be31e24331b6ec7398a2d16eff061123.png)
![](https://img-blog.csdnimg.cn/img_convert/16a72c0924189ee1d511a0be212979e4.png)
![](https://img-blog.csdnimg.cn/img_convert/de8e04f48187730054674e958213f5bb.png)
![](https://img-blog.csdnimg.cn/img_convert/b5c923d3d80e199fadb8524fbd3e4dd8.png)
![](https://img-blog.csdnimg.cn/img_convert/8feaccf272803ba94b435dce4213971f.png)
![](https://img-blog.csdnimg.cn/img_convert/a94894b42497f50b1bde104e7513719f.png)
其他选择器
![](https://img-blog.csdnimg.cn/img_convert/0fe010eb40776c58ae7464268a3d378b.png)
类选择器:允许重复,相同名称具有相同效果格式如下
![](https://img-blog.csdnimg.cn/img_convert/22e1a018bdef4b5428a61ebee2f1299e.png)
标签选择器:标签可以直接使用,相同标签全部被选择格式如下
![](https://img-blog.csdnimg.cn/img_convert/3ad139d3d3c1edf6d43ff8bbf9acca77.png)
id选择器:为了方便使用是不允许重复,语法上允许,唯一的选择器,格式如下#+id。
![](https://img-blog.csdnimg.cn/img_convert/19fd31309cecc402f5aaf50bf5d2cdfe.png)
*号选择器:对所有的内容进行控制。
![](https://img-blog.csdnimg.cn/img_convert/ea3deb3f925794cd5da6d555b14b637e.png)
逗号选择器:逗号可以连续对多个标签使用相同效果
![](https://img-blog.csdnimg.cn/img_convert/d2b38edf6ab15d0aa54d0030acd1cde5.png)
空格选择器:选中某个id内所有的某类元素,下图选中div元素下的所有P标签。
![](https://img-blog.csdnimg.cn/img_convert/4bd947124bb6fd6e9ba62e2b56c1b898.png)
>选择器:直接选择div1下的,孙子不选
![](https://img-blog.csdnimg.cn/img_convert/8e45e5654961723f9b0d060958ce06c3.png)
+选择器:和div是同一级的p直接都被选中。
![](https://img-blog.csdnimg.cn/img_convert/2ef86c04da39c7a425c65ded4d16f945.png)
属性选择器:和类选择等类似
![](https://img-blog.csdnimg.cn/img_convert/fd704bb18b2ed3e0c24cee9bba32d24d.png)
选择器的优先级排序
![](https://img-blog.csdnimg.cn/img_convert/ee02ced6a6a3644e4911fc1c5d3ebc7d.png)
important代表强制优先级提升。
规律:选择范围越小优先级越高
盒子模型
![](https://img-blog.csdnimg.cn/img_convert/22fe6f1165587d6eea7bc453e9de6443.png)
![](https://img-blog.csdnimg.cn/img_convert/d817f2b74425a287a14021d4b89d0a55.png)
![](https://img-blog.csdnimg.cn/img_convert/85c44dcb43633ac15d6e604244579f9d.png)
![](https://img-blog.csdnimg.cn/img_convert/0efe9a8740080efbc2d613845900f521.png)
![](https://img-blog.csdnimg.cn/img_convert/371a88f766b8bf9622c45f6f006405fb.png)
![](https://img-blog.csdnimg.cn/img_convert/4a2d651be26f49bb56b0764188177b92.png)
![](https://img-blog.csdnimg.cn/img_convert/f8d8c8b0b93c90ec86672781425e4199.png)
![](https://img-blog.csdnimg.cn/img_convert/173f7c4926de7cf7d3b3863bebba2592.png)
![](https://img-blog.csdnimg.cn/img_convert/4cea0ec412d0a17e778a8af8f1fe8608.png)
![](https://img-blog.csdnimg.cn/img_convert/443ea1e440035bd7c8326e9959d52970.png)
![](https://img-blog.csdnimg.cn/img_convert/1afd5a0caa8a5b7494231f686e4c398e.png)
![](https://img-blog.csdnimg.cn/img_convert/69043c2e9c4c93c21ee46c88781d3c57.png)
![](https://img-blog.csdnimg.cn/img_convert/854a95a146fcceb7af564cea07269085.png)
![](https://img-blog.csdnimg.cn/img_convert/edf61259a513847cc778aeebf1d15d02.png)
![](https://img-blog.csdnimg.cn/img_convert/aa73739f79e7febcc44e6340d01e2727.png)
![](https://img-blog.csdnimg.cn/img_convert/60a85aedbf5df114683803e633cb8f7b.png)
![](https://img-blog.csdnimg.cn/img_convert/1a2228480b5a2390596a63bebc31a58a.png)
![](https://img-blog.csdnimg.cn/img_convert/1e3494765e393be32be44397511d758f.png)
![](https://img-blog.csdnimg.cn/img_convert/3a59b9a2f0e44bf5af9f35f12ab7a5ad.png)
![](https://img-blog.csdnimg.cn/img_convert/b66db1fe06f1d54dd2cff1365e84e727.png)
![](https://img-blog.csdnimg.cn/img_convert/5e2b0cd1b1a5a7f04d2e7f4027f80815.png)
一、块元素block
块元素——div、p、h1-h6、ul、ol、li
所有的块级元素独占一行显示
可以设置宽高
二、行内元素inline
行内元素——span、a、font、strong、em、i
所有的行内元素都在一行上显示
不能设置宽高、由内容撑开
三、行内块inline-block
行内块——img、input
可以设置宽高、并且在一行上显示
默认对齐的是基线
![](https://img-blog.csdnimg.cn/img_convert/22340322935eb4adf8d3ea286af76333.png)
![](https://img-blog.csdnimg.cn/img_convert/5060e3db233d12b34b5458fe13d2bde0.png)
![](https://img-blog.csdnimg.cn/img_convert/16ff6feaf54c1eb20a77f631ceab6aee.png)
![](https://img-blog.csdnimg.cn/img_convert/35b443082fd350a4e2990ed6693047b8.png)
![](https://img-blog.csdnimg.cn/img_convert/d360b9f97e49d6a07cfaabd613d16650.png)
![](https://img-blog.csdnimg.cn/img_convert/83787d9333d6d887c7a543607b8b1345.png)
![](https://img-blog.csdnimg.cn/img_convert/fda5b5270c7adb4bf96e19c9d769b391.png)
![](https://img-blog.csdnimg.cn/img_convert/cefd3c35f6d48aaa972e5881f9d8b0d5.png)
![](https://img-blog.csdnimg.cn/img_convert/51e5aaf1eb3fed5b5f1a58cdcf6f6113.png)
![](https://img-blog.csdnimg.cn/img_convert/ce586720a0a8482e19b9f5a4986eaabf.png)
![](https://img-blog.csdnimg.cn/img_convert/fe56b3f5bae2066c0593a6be216a3489.png)
![](https://img-blog.csdnimg.cn/img_convert/9f6b708dd026ed00ca52072d38a5bd39.png)
![](https://img-blog.csdnimg.cn/img_convert/017e390847df0aca6091f5c1b1d6c54b.png)
![](https://img-blog.csdnimg.cn/img_convert/8629bb6a42efc8e742ab202b4e55b7f8.png)
![](https://img-blog.csdnimg.cn/img_convert/db6e8867305e41dcf9168cb91625146c.png)
![](https://img-blog.csdnimg.cn/img_convert/478644ad891cb58260d44c4772e2e8a0.png)
![](https://img-blog.csdnimg.cn/img_convert/45d56225a515c38378dc512ec8b57f9b.png)
![](https://img-blog.csdnimg.cn/img_convert/6351bda26264c9143ce0b3c1c17ad1ae.png)
![](https://img-blog.csdnimg.cn/img_convert/0f81aca02416800325c1039f092f2618.png)
![](https://img-blog.csdnimg.cn/img_convert/4fed6cec8bf21ca513e3630d6df8825f.png)
![](https://img-blog.csdnimg.cn/img_convert/314f7d3f0391a30294718436dbf72190.png)
![](https://img-blog.csdnimg.cn/img_convert/39d6c50b64beaac4f926cdc9084d156b.png)
![](https://img-blog.csdnimg.cn/img_convert/ebfc663bd3796e4c3b1a0e4fc9ff5141.png)
![](https://img-blog.csdnimg.cn/img_convert/3447072d95acebb22ae070656a613322.png)
![](https://img-blog.csdnimg.cn/img_convert/5a16e698b5c1d8aca41b7606f0759ba9.png)
![](https://img-blog.csdnimg.cn/img_convert/8ee6b8e06b94ce06d2795252ff38e74f.png)
![](https://img-blog.csdnimg.cn/img_convert/4ce33343eaabcbc300ce4a7b7947b0a4.png)
![](https://img-blog.csdnimg.cn/img_convert/227d4b34062a01334779347041e3240b.png)
![](https://img-blog.csdnimg.cn/img_convert/7eaa33740879956a1e01f7d2f57e3e36.png)
![](https://img-blog.csdnimg.cn/img_convert/c9ce973fe4b1291d238ccfe19767eaa2.png)
![](https://img-blog.csdnimg.cn/img_convert/85a2700417e6d1df1f20e40bf4ff27bd.png)
![](https://img-blog.csdnimg.cn/img_convert/911c0b4be7457feda2236c950a7061d1.png)
![](https://img-blog.csdnimg.cn/img_convert/1bec186e9d48afcff29b5c976d7c18b6.png)
![](https://img-blog.csdnimg.cn/img_convert/7abfa9501ed04429f51ab6aac75be965.png)
<style>
body{
background-color: #eee;
}
li{
float: left;
list-style: none;
width: 280px;
height: 280px;
margin: 10px;
text-align: center;
padding: 20px;
background-color: #fff;
}
li img{
width: 260px;
}
p{
color: #707070;
font-size: 20px;
}
</style>
</head>
<body>
<h1>诱惑美食</h1>
<ul>
<li>
<p>Country bread with dry figs</p>
<img src="./images/1.jpg" alt="">
<a href="#">Free Download</a>
</li>
<li>
<p>Fruits</p>
<img src="./images/2.jpg" alt="">
<a href="#">Free Download</a>
</li>
<li>
<p>Bell Pepper</p>
<img src="./images/3.jpg" alt="">
<a href="#">Free Download</a>
</li>
<li>
<p>Oranges</p>
<img src="./images/4.jpg" alt="">
<a href="#">Free Download</a>
</li>
<li>
<p>Healthy breakfast</p>
<img src="./images/5.jpg" alt="">
<a href="#">Free Download</a>
</li>
<li>
<p>Homemade Cupcakes</p>
<img src="./images/6.jpg" alt="">
<a href="#">Free Download</a>
</li>
<li>
<p>Strawberries</p>
<img src="./images/7.jpg" alt="">
<a href="#">Free Download</a>
</li>
<li>
<p>Custard Croissant</p>
<img src="./images/8.jpg" alt="">
<a href="#">Free Download</a>
</li>
</ul>
</body>
![](https://img-blog.csdnimg.cn/img_convert/2588261407f153e83ffc6dd440ba27d7.png)
![](https://img-blog.csdnimg.cn/img_convert/f05f316c5810905c5b7a014ba2ba720a.png)
难点:ul没有设置高度,高度为0,造成下标题紧接着块元素下边,导致乱码,设置高度700后,如果缩小窗口高度700又会造成乱码,所以高度应该随窗口变化。
![](https://img-blog.csdnimg.cn/img_convert/41101816603905ed787a2dfa2d831155.png)
![](https://img-blog.csdnimg.cn/img_convert/fc371810d268127fa5ffae498474b85e.png)
![](https://img-blog.csdnimg.cn/img_convert/69b37292984108b7314dd25eca0390cc.png)
<style>
.one {
float: left;
width: 200px;
height: 200px;
background-color: orange;
}
.two {
float: left;
width: 300px;
height: 300px;
background-color: blue;
}
.erba {
width: 600px;
height: 200px;
background-color: green;
}
.three {
clear: both;
}
</style>
</head>
<body>
<div class="father">
<div class="one"></div>
<div class="two"></div>
<!-- 通过第三个盒子将一行浮动效果固定下来,但却可以横向排列 -->
<div class="three"></div>
</div>
<div class="erba"></div>
</body>
![](https://img-blog.csdnimg.cn/img_convert/b8c665f104ce23ab5380bf10433e0c3d.png)
![](https://img-blog.csdnimg.cn/img_convert/4986b975f1b2c079e95b1190e99708ba.png)
![](https://img-blog.csdnimg.cn/img_convert/b59dc43c37392fa07d86b19e3737fe7c.png)
![](https://img-blog.csdnimg.cn/img_convert/cd788208beb5aec7f1fe39dd2e6eac4e.png)
![](https://img-blog.csdnimg.cn/img_convert/d3beb5816a98d41820bcc6a4b849bbe0.png)
![](https://img-blog.csdnimg.cn/img_convert/8f49b506dcbef78068df248f393aac34.png)
![](https://img-blog.csdnimg.cn/img_convert/ccf63680f661081dd73780e0642fd79b.png)
![](https://img-blog.csdnimg.cn/img_convert/1b8a5cb59cef370b2abf120b0113eccf.png)
![](https://img-blog.csdnimg.cn/img_convert/c489430ba818866e12a96e6be3e08852.png)