今天学习了一些css小知识,来实践一下吧!
一、CSS的字体
1.字体选择 font-family
body {
font-family: 'Microsoft Yahei', tahoma, arial, 'Hiragino Sans GB';
}
- Microsoft YaMei
- 多个字体用,隔开
- 多个单词组成字体,用‘ ’隔开,单引双引都可以
- 多直接body设置字体
- 字体第一个显示不出来,就直接看第二个
2.字体大小 font-size
- px(像素)为网页最常用的单位
- 谷歌默认字体大小16px
- body指定整个页面大小
- 标题标签特殊,需要格外指定
3.字体粗细 font-weight 通常喜欢用数字
font-weight: 700;
- 700不要带单位,等价于bold
- bold加粗
- 多用数字
- 400和normal等价
4.文字样式 font-style
- normal 默认 变不倾斜
- italic 倾斜(不常用)
5.复合属性 简写font:font-style font-weight font-size/line-height font-family
- font:font-style font-weight font-size/line-height font-family顺序不可更改,空格隔开
- 例如:font : italic 700 16px/20px 'microsoft yamei'
- 属性都可省略,只有font-size和font-family不可省略
- font:16px 'microsoft yahei'
二、CSS的文本
1.文本颜色 color
div{
color: red;
color: #ff0000;
color: rgb(250,0,0);
}
2.对齐文本 text-align
3.装饰文本 text-decoration
4.文本缩进 text-indent : 2em
- em是一个相对单位,一个文字的大小
5.行高 line-height:12px; line-height:2;
- line-height:1.5;代表当前文字大小font-size的1.5倍。
- font-size:16px;则行高为16*1.5
三、CSS的背景
1.背景颜色 background-color 默认透明transparent
2.背景图片 background-image 可url指定图片
background-image: url(images/pic.jpg);
3.背景平铺 background-repeat
- 默认平铺repeat
-
background-repeat: no-repeat;不平铺
4.背景图片位置 background-position:x y;
background-position:x y;
- x y 为坐标,可填
1)方位名词 right center
background-position: right center;
- 俩个值都是方位名词,顺序无所谓。
- 只写一个方位名词,默认第二个居中。
2)精确数值 按x y顺序写
background-position: 20px 50px;
- x为20,y为50
3)混合单位 20px center
background-position: 20px center;
- x为20,y居中
5.背景固定 background-attachment: fixed;
background-attachment: fixed;
- scroll 随内容滚动
- fixed 背景图像固定
6.背景复合写法 background:背景颜色 背景图片地址 背景平铺 背景图像滚动 背景图片位置
background: pink url(images/wz.jpg) no-repeat fixed center top;
7.背景色半透明 background: rgba(0, 0, 0, 0.5)
- 最后一个参数alpha透明度,取值范围在0~1之间。
- 0.5可以把零省略,写成.5