重点:
1、背景属性
css背景属性主要有以下几个:
| 属性 | 描述 |
|---|---|
| background-color | 设置背景颜色 |
| background-image | 设置背景图片 |
| background-repeat | 设置背景图片如何填充,必须先指定background-image |
| background-size | 设置背景图片大小,必须先指定backgroun-image |
| background-position | 该属性设置背景图片的起始位置 |
| background | 复合属性 |
background-color属性
该属性设置背景颜色
.box{width:300px;height:300px;background-color:red;}<div class="box"></div>
颜色值:
- 单词:red、green
- 十六进制:#000000、#ffffff
- 颜色通道:rgb(255,255,255)、rgba(255,255,255,0.5)
<a name="B5hmp"></a>### background-repeat属性该属性设置如何平铺背景图像| 值 | 描述 || --- | --- || repeat-x | 水平方向平铺 || repeat-y | 垂直方向平铺 || no-repeat | 不平铺 |```css.box{width: 600px;height: 600px;background-image: url("images/img1.jpg");background-repeat: no-repeat;}
background-size属性
该属性设置背景图像的大小
| 值 | 描述 |
|---|---|
| percentage | 百分比 |
| cover | 此时会保持图像的纵横比并将图像缩放成将完全覆盖背景定位区域的最小大小 |
| contain | 此时会保持图像的纵横比并将图像缩放成将适合背景定位区域的最大大小 |
.box{width: 600px;height: 600px;background-image: url("images/img1.jpg");background-repeat: no-repeat;background-size: 100% 100%;}
background-position属性
该属性设置背景图像的起始位置,其默认值是:0% 0%
| 值 | 描述 |
|---|---|
| left top | 左上角为基准 |
| left center | 左 中 |
| left bottom | 左 下 |
| right top | 右 上 |
| right center | 右 中 |
| right bottom | 右 下 |
| center top | 中 上 |
| center center | 中 中 |
| center bottom | 中 下 |
| x% x% | 百分比 |
.box{width: 600px;height: 600px;background-image: url("images/img1.jpg");background-repeat: no-repeat;background-position: center;}
background复合属性
background-image、background-repeat、background-position其中background-size单独书写
2、字体属性
color
规定字体的颜色
div{ color:red;}div{ color:#ff0000;}div{ color:rgb(255,0,0);}div{ color:rgba(255,0,0,.5);}
font-size
设置字体的大小
h1 {font-size:40px;}h2 {font-size:30px;}p {font-size:14px;}
font-weight
设置字体的粗细
| 值 | 描述 |
|---|---|
| 100~900 | 数值的粗细 |
| bold | 定义粗体 |
H1 {font-weight:normal;}div{font-weight:bold;}p{font-weight:900;}
font-family
font-family属性指定一个元素的字体
p{font-family:"Microsoft YaHei","Simsun","SimHei";}
3、文本属性
text-align
指定元素文本的水平对齐方式
| 值 | 描述 |
|---|---|
| left | 左对齐 |
| right | 右对齐 |
| center | 居中 |
4、列表属性
list-style-type
属性设置列表项标记的类型。
| 值 | 描述 |
|---|---|
| none | 无标记 |
| disc | 默认,实心圆 |
| circle | 空心圆 |
| square | 实心方块 |
ul.a {list-style-type: circle;}ul.b {list-style-type: square;}
