发布时间:2025-12-10 13:00:12 浏览次数:7
在网页设计中,背景是一个十分重要的元素,如果能合理地运用背景css代码,不仅能够美化页面,还能够提高页面的可读性和用户体验。下面介绍几个背景css代码的编写方法:
/* 1. 单色背景 */body {background-color: #F5F5DC;}/* 2. 渐变色背景 */body {background: linear-gradient(to bottom, #32CD32, #FF6347);}/* 3. 图片背景 */body {background-image: url("example.jpg");/* 设置图片不平铺 */background-repeat: no-repeat;/* 图片定位 */background-position: center;}/* 4. 背景大小 */body {background-size: cover;}/* 5. 背景透明度 */body {background-color: rgba(255, 255, 255, 0.5);}/* 6. 背景固定 */body {background-attachment: fixed;}