一:CSS选择器
标签选择器:
标签 {
}
类选择器:
class=" 类名 "
.类名 {
}
id选择器:
id="id名"
#id名 {
}
通配符选择器:
* {
}
后代选择器:
父标签 (子标签 ) 子标签的子标签 {
}
子元素选择器:
父标签>子标签 >子标签的子标签 {
}
并集选择器:
标签1,标签2 {
}
链接伪类选择器:
a:link(选择所有未被访问过的链接) {
}
a:visited(选择所有已被访问过的链接) {
}
a:hover(选择鼠标指针位于其上的链接) {
}
a:active(选择鼠标按下未弹起的链接) {
}
focus伪类选择器:
input:focus(选择获得光标的表单) {
background-color:red;
color:blue;
...............
}
二:CSS各属性
1:字体属性(font)
font-family:设置字体系列
font-family: 'Microsoft Yahei'( '微软雅黑'),'Arial','Helvetica';
font-size:设置字体大小
font-size: .....px;
font-weight:设置字体粗细
font-weight:normal(正常值,也是默认值)/bold(加粗)/bolder(特粗)/lighter(细体);
font-weight:400(正常)/700(加粗);(具体数值100~900)
font-style:设置文字样式
font-style: normal(正常)/italic(斜体);
font设置字体复合属性
font:font-style font-weight font-size/line-height font-family;
必须保留font-size和font-family属性,其他属性可以省略(即设置为默认值)
2:文本属性(text)
color设置文本颜色
color:blue;
color:#ff0000;
color:rgb(200,0,0);
text-align设置文本的水平对齐方式
text-align:left/center/right;
text-decoration设置文本修饰
text-decoration:none(无修饰,默认值)/underline(下划线)/overline(上划线)/line-through(删除线);
text-indent设置文本缩进
text-indent:20px;
text-indent:2em;
line-height设置行间距
line-height:20px;
3:背景属性(background)
background-color设置背景颜色
background-color:颜色值(默认为transparent,透明色);
background-image设置背景图片
background-image: url(图片地址);
backcground-repeat设置背景平铺
background-repeat:repeat(平铺)/no-repeat(不平铺)/repeat-x(沿X轴平铺)/repeat-y(沿Y轴平铺);
background-position设置背景位置
background-position:x y;
(top/bottom/left/right/center;)/(20px;)
background-attachment设置背景固定
background-attachment:scroll(滚动,默认值)/fixed(固定);
background设置背景复合写法
background:背景颜色 背景图片地址 背景平铺 背景固定 背景位置;
background:rgba()设置背景颜色半透明
background:rgba(0,0,0,0.3);
三:盒子模型
1:边框(border)
border-width(边框粗细):20px;
border-style(边框样式):solid(实线)/dashed(虚线)/dotted(点线);
border-color(边框颜色):red;
复合写法:
border:border-width border-style border-color;
border-collapse细线边框
border-collapse:collapse;表示相邻边框合并在一起(多用于表格);
2:内边距(padding)
padding:所有内边距;
padding:上下内边距,左右内边距;
padding:上内边距,左右内边距,下内边距;
padding:上内边距,右内边距,下内边距,左内边距;
3:外边距(margin)
margin: 0 auto;(把盒子水平居中)
4:清除网页元素的内外边距
* {
padding:0;
margin:0;
}
5:圆角边框:(border-radius)
border-radius:length;
6:盒子阴影(box-shadow)
box-shadow:h-shadow(必需) v-shadow(必需) blur spread color inset;
7:文字阴影(text-shadow)
text-shadow:h-shadow(必需) v-shadow(必需)blur color;