background组合使用
<div style="
width: 100px;
height: 100px;
/* 顺序为 background-color background-image background-repeat background-attachment background-position */
background: #00ff00 url('smiley.gif') no-repeat fixed center;
"></div>
background常用属性
| 属性 | 描述 | 值 | 说明 |
|---|---|---|---|
| background-color | 设置元素的背景色。 | ||
| color-name | 颜色的因为名 | ||
| color-rgb | rga | rgba | ||
| color-hex | 十六进制 | ||
| transparent | 透明色 | ||
| background-image | 设置背景图像。 |
url(URL) | png|gif|jpeg 等图片格式 |
|
linear-gradient |
背景渐变 | ||
| none | 不设置背景图片 | ||
| background-repeat | 设置背景图像是否及如何重复。 | repeat | 水平、垂直重复 |
| repeat-x | 水平重复 | ||
| repeat-y | 垂直重复 | ||
| no-repeat | 不重复 | ||
| space | 背景图片对称均匀分布 | ||
| background-attachment | 背景图像是否固定或者随着页面的其余部分滚动。 | scroll | 背景滚动 |
| fixed | 背景固定 | ||
| background-position | 设置背景图像的起始位置。 | left | 左对齐 |
| right | 右对齐 | ||
| center | 居中对齐 | ||
| top | 顶端对齐 | ||
| bottom | 底部对齐 | ||
| 水平居中方式 垂直居中方式 | 设置水平垂直居中方式 | ||
| x% y% | 自己设置位置 | ||
| background-size | 背景的尺寸 | cover | 背景完全覆盖,可能会有背景溢出 |
| contain | 图片不溢出的放在容器中,可能会漏出部分区域 | ||
|
background-clip | 图片裁剪 | border-box | 包括边框 |
| padding-box | 不包括边框,包括内边距 | ||
| center-box | 内容区域 |
本文详细解读CSS背景属性,包括background-color、background-image、repeat、attachment和position等,教你如何创建复杂的网页布局和设计。
3137

被折叠的 条评论
为什么被折叠?



