css中设置背景代码

发布时间:2025-12-10 12:59:31 浏览次数:5

CSS中的背景设置使用CSS可以让网页的背景呈现出丰富多彩的效果。下面就是一些常用的CSS背景设置代码:

设置背景颜色:

body {background-color: #f1f1f1;}

设置背景图片:

body {background-image: url("background.jpg");}

设置背景图片显示方式:

body {background-image: url("background.jpg");background-repeat: no-repeat;background-size: cover;}

设置背景图片的位置:

body {background-image: url("background.jpg");background-repeat: no-repeat;background-position: center;}

设置固定背景图片:

body {background-image: url("background.jpg");background-attachment: fixed;}

设置渐变背景色:

body {background: linear-gradient(to bottom right, #ff0080, #3f26a4);}
以上是一些较为常用的CSS设置背景的代码,根据需求可以进行调整和组合使用。

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477