一、选择器
<title>CSS</title>
<style>
p{
color:red;
}
</style>
<p></p>
<title> </title>
<style>
.red{
color: aliceblue;
}
</style>
<div class="red"></div>
<title> </title>
<style>
#red{
color: aliceblue;
}
</style>
<div id="red"></div>
*{
clolr:red
}
二、 文字控制属性
<title> </title>
<style>
p{
}
</style>
width | 宽 |
height | 高 |
background-color | 背景色 |
字大小 font-size:
单位px (Google默认16px)
字粗细 font-weight:
数字 | 关键字 |
---|
正常 400 | normal |
加粗 700 | bold |
倾斜 font-style:
行高 line-height:
数字+px | 数字(当前font-size属性值的倍数) |
如 : line-height: 30px ; | 如 :line-height: 2 ; (当前字体大小16px) |
字体族 font-family:
如 font-family: 楷体 ;
div{
font:italic 700 30px/2 楷体;
}
文字缩进 text-indent:
数字+em(1em=当前字体大小)
文本对齐text-align:
left | 左对齐 |
center | 居中对齐 |
right | 右对齐 |
图片对齐
<title> </title>
<style>
div{
text-align: center;
}
</style>
<div>
<img src="#" alt="">
</div>
文本修饰线 text-decoration:
none | 无 |
underline | 下划线 |
line-through | 删除线 |
overline | 上划线 |
颜色文字 colos:
颜色单词 | red、green... |
rgb(r,g,b) | 红绿蓝,取值0-255 |
ragb(r,a,g,b) | a透明度,取值0-1 |
十六进制#RRGGBB | #000000、#ffcc00(#000、#fc0) |
三、 复合选择器
后代选择器
<title>标题</title>
<style>
div span{
color: black;
}
</style>
<body>
<span>span标签</span>
<div>
<span>这是div后代span</span>
</div>
</body>
四、 伪类选择器
鼠标悬停选择器:hover
<style>
a:hover{
color: brown;
}
</style>
<body>
<a href="#">悬停内容</a>
</body>
L V H A顺序
:link | 访问前 |
:vistied | 访问后 |
:hover | 鼠标悬停 |
:active | 点击时(激活) |
相同属性覆盖。后面的CSS覆盖前面;
不同属性叠加,都生效CSS