小编给大家分享一下CSS设置背景属性的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
背景相关属性主要有:
background-color 背景颜色
background-image 背景图片
background-repeat 是否平铺 repeat (默认平铺) | repeat-x(水平平铺) | repeat-y (垂直平铺)| no-repeat (不平铺)
background-position 背景位置 length(百分数)|position(top center button left right) 一般两个一起用,如果至指定一个方向另一个方向默认为center,两种方法也可以混搭。方位名词没有顺序区分,而使用百分数时时有顺序的,先是水平后是垂直
background-attachment 背景固定还是滚动 scroll | fixed
background:背景颜色 背景图片 是否平铺 背景固定还是滚动 背景位置
#p1 {
width: 300px;
height: 300px;
background-color: blue; /*默认是transparent透明的*/
/* background-color: transparent; */
background-image: url(Images/2.jpg);
background-repeat: no-repeat; /*不平铺,默认是水平垂直平铺*/
/* background-repeat: repeat-y; */
/* background-repeat: repeat-x; */
/* background-position: right bottom; */
background-position: 10% center;
background-attachment: fixed;
}
想要背景半透明 在指定颜色时使用 rgba( r, g b ,a) ,a就是指明透明度
p {
width: 100%;
height: 300px;
background-color: rgba(0, 0, 0, 0.6);
}
当要使用多张背景图片时使用background来指定多个url,每组之间用‘,’逗号隔开,若图片有重叠,则前一张覆盖后一张图片,但是整体背景颜色必须在最后一个url后指定。
p {
width: 100%;
height: 300px;
background: url(Images/2.jpg) no-repeat left top, url(Images/3.jpg) no-repeat right bottom blue;
}
看完了这篇文章,相信你对CSS设置背景属性的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。