伪类选择器
<style>
a:link {
color: #FF0000;
}
a:hover {
color: #FF00FF
}
a:active {
color: #0000FF
}
a:visited {
color: #00FF00
}
input:focus {
outline: none;
background-color: #eee;
}
a {
text-decoration: none;
}
</style>
伪元素选择器
<style>
p:first-letter {
font-size: 48px;
color: orange;
}
p:before {
content: '你说的对';
color: blue;
}
p:after {
content: '雨露均沾';
color: orange;
}
ps:before和after通常都是用来清除浮动带来的影响:父标签塌陷的问题
</style>
选择器的优先级
<style>
.c1{
color: blue;
}
#d1{
color: red;
}
p{
color: blueviolet;
}
</style>
<body>
<p id="d1" class="c1" style="color: chartreuse">关关雎鸠在河之洲,</p>
</body>
CSS相关属性
<style>
p{
background-color: red;
height: 200px;
width: 400px;
}
span{
background-color: chartreuse;
height: 200px;
width: 100px;
}
</style>
字体属性
p{
font-family: "Adobe 宋体 Std L","微软雅黑 Light",serif;
font-size: 20px;
font-weight: inherit;
color: red;
color: #ee762e;
color: rgb(128,23,45);
color: rgba(23, 128, 91, 0.9);
opacity:0.1
}
font-weight用来设置字体的字重(粗细)。
值 描述
normal 默认值,标准粗细
bold 粗体
bolder 更粗
lighter 更细
100~900 设置具体粗细,400等同于normal,而700等同于bold
inherit 继承父元素字体的粗细值
文字属性
<style>
p{
text-align: center;
text-align: left;
text-align: right;
text-align: justify;
text-decoration: underline;
text-decoration: overline;
text-decoration: line-through;
text-decoration: none;
text-indent: 32px;
}
</style>
背景图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#d1{
height: 200px;
background-color: red;
}
#d2{
height: 200px;
background-color: chartreuse;
}
#d3{
height: 200px;
background-color: blueviolet;
}
#d4{
height: 100px;
background-color: red;
background-attachment: fixed;
background-image: url("preview.jpg");
}
#d5{
height: 200px;
background-color: brown;
}
#d6{
height: 200px;
background-color: aqua;
}
#d7{
height: 200px;
background-color: darksalmon;
}
</style>
</head>
<body>
<div id="d1">关关雎鸠,在河之洲</div>
<div id="d2">窈窕淑女,君子好逑</div>
<div id="d3">参差荇菜,左右流之</div>
<div id="d4">窈窕淑女,寤寐求之</div>
<div id="d5">求之不得,寤寐思服</div>
<div id="d6">优哉游哉,辗转反侧</div>
<div id="d7">参差荇菜,左右流之</div>
</body>
</html>
边框
边框属性
● border-width
● border-style
● border-color
<style>
p{
border-width: 5px;
border-style: dashed;
border-color: darksalmon;
border-left-width: 10px;
border-left-style: solid;
border-left-color: blueviolet;
border-top-width: 5px;
border-top-style: dashed;
border-top-color: green;
border-right-width: 5px;
border-right-style: dashed;
border-right-color: orange;
border-bottom-width: 5px;
border-bottom-style: dashed;
border-bottom-color: brown;
width: 400px;
height: 400px;
border: 5px solid red;
background: red;
border-radius: 25%;
border-top-left-radius: 100px;
border-top-right-radius: 100px;
border-bottom-left-radius: 100px;
border-bottom-right-radius: 100px;
}
</style>
display属性(重要)
<style>
#d1{
height: 200px;
background-color: red;
text-align: center;
display: none;
display: inline-block;
visibility: hidden;
}
#d2{
height: 200px;
background-color: chartreuse;
text-align: center;
display: inline-block;
}
</style>
<body>
<div id="d1">关关雎鸠,在河之洲</div>
<div id="d2">窈窕淑女,君子好逑</div>
</body>
CSS盒子模型
"""
盒子模型
就以快递盒为例
快递盒与快递盒之间的距离(标签与标签之间的距离 margin外边距)
盒子的厚度(标签的边框 border)
盒子里面的物体到盒子的距离(内容到边框的距离 padding内边距)
物体的大小(内容 content)
如果你想要调整标签与标签之间的距离 你就可以调整margin
浏览器会自带8px的margin,一般情况下我们在写页面的时候,上来就会先将body的margin去除
"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
}
#d1 {
margin-bottom: 50px;
}
#d2 {
margin-top: 20px;
}
#dd {
margin: 0 auto;
}
p {
border: 3px solid red;
}
</style>
</head>
<body>
<p>ppp</p>
</body>
</html>
浮动
"""浮动的元素 没有块儿级一说 本身多大浮起来之后就只能占多大"""
只要是设计到页面的布局一般都是用浮动来提前规划好
<style>
body {
margin: 0;
}
#d1 {
height: 200px;
width: 200px;
background-color: red;
float: left;
}
#d2 {
height: 200px;
width: 200px;
background-color: greenyellow;
float: right;
}
</style>
浮动带来的问题以及解决办法
谁塌陷就给谁加一下代码
.clearfix:after {
content: "";
display: block;
clear: both;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY