千仲峰 2026-05-07 10:27:02
背景颜色:background-color: #ff0000; 红色背景 背景图片:background-image: url('image.jpg'); 使用图片做背景 背景重复:background-repeat: no-repeat; 不重复背景图片 背景位置:background-position: 50% 50%; 背景居中 背景附件:background-attachment: fixed; 背景固定不动 背景大小:background-size: cover; 背景覆盖整个元素
288 赞
血战メ傲神 2026-05-04 16:34:29
CSS背景属性,简单来说就是设置网页元素的背景样式。常用背景属性包括:
1. background-color:设置背景颜色。
- 示例:background-color: #f00; (红色)
2. background-image:设置背景图片。 - 示例:background-image: url('image.jpg');
3. background-repeat:设置背景图片的平铺方式。 - 示例:background-repeat: no-repeat; (不平铺)
4. background-position:设置背景图片的位置。 - 示例:background-position: center center; (居中)
5. background-size:设置背景图片的大小。 - 示例:background-size: cover; (覆盖整个元素)
6. background-attachment:设置背景图片是随元素滚动还是固定。 - 示例:background-attachment: fixed; (固定)
7. background-origin:设置背景定位的基准区域。 - 示例:background-origin: padding-box; (从内边距开始定位)
8. background-clip:设置背景图片的裁剪区域。 - 示例:background-clip: border-box; (裁剪到边框)
9. background:将所有背景属性合并写在一起。 - 示例:background: #f00 url('image.jpg') no-repeat center center;
用起来很简单,对吧?你自己看怎么用吧。
253 赞