您好,欢迎来到UU财经。
搜索
您的当前位置:首页CSS如何设置背景属性(详解)

CSS如何设置背景属性(详解)

来源:UU财经


本文给大家详解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;
     }

    总结:

    Copyright © 2019- uude.cn 版权所有

    违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

    本站由北京市万商天勤律师事务所王兴未律师提供法律服务