这是我参与「第四届青训营 」笔记创作活动的的第2天
CSS是用来定义页面元素的样式,如设置字体和颜色,位置和大小,添加动画效果等。
在页面中使用css:
1.外链:通过link标签将外部文件嵌入
<link rel = "stylesheet" herf = "style.css">
2.嵌入:将样式的代码嵌入到style标签中
<style>
li{}
<style>
3.内联:直接将样式写在当前标签的style属性里面
<p style = " "></p>
选择器Selector
找出页面中的元素,以便是指样式 按照标签名、属性、Dom树种的位置等选择元素
通配选择器
通过*来匹配所有
**id选择器**
通过id(id唯一)
**类选择器**
同一类型的标签设置样式
<li class = "done"></li>
.done{color:red;...}
**属性选择器**
只要有指定的属性就选中
如果要指定属性等于特定的值:[type="password"]
<input type="password" value ="123456" />
<style>
input[type="password"]{color:red}
</style>
a[herf^="#"]以井号开头的都会被匹配
a[herf$=".jpg"]以指定的结尾则匹配
伪类
不基于标签和属性定位元素 a:link{color:grey;} a:hover{color:red;} RGB
调整三原色的值 两种写法: rgb(74,57,104) #4a3968(对应十六进制) alpha透明度
font-family设置多个字体,方便多个设备访问
font-family:Optima...
font-size
三种写法: section{ font-size: 20px;} font-size: 2em font-size:80% em没有指定最小看父级 section20px则20*2
talic斜体
Font-weight:100...设置字体粗细400=normal 7 00-bold
Line-height: 行高
White -space 换行