首页 > 其他分享 >CSS11.背景

CSS11.背景

时间:2023-03-24 19:23:47浏览次数:32  
标签:repeat center CSS11 url 背景 background position

CSS背景

1.背景颜色(color)

  • 语法:

background-color:颜色值;   默认的值是 transparent 透明的
例:background-color:pink;

 

2.背景图片(image)

  • 语法:

background-image:none|url(url)
参数作用
none 无背景图(默认的)
url 使用绝对或相对地址指定背景图像

背景图片是在背景的底部

    background-image:url(images/demo.png);
例: background-image:url(images/l.jpg);
  • 小技巧:我们提倡背景图片后面的地址,url不要加引号。例:url(“images/demo.png”)❌

 

3.背景平铺(repeat)

  • 语法:

background-repeat:repeat | no-repeat | repeat-x | repeat-y
参数作用
repeat 背景图像在纵向和横向上平铺(默认的)
no-repeat 背景图像不平铺
repeat-x 背景图像在横向上平铺
repeat-y 背景图像在纵向上平铺

 

4.背景位置(position)重点

  • 语法:

background-position:length || length
background-position:position || position

background-position:x坐标 y坐标(位置可以改变);
background-position:right top;  /*右上角*/
background-position:left bottom;  /*左下角*/
background-position:center center;  /*正中心*/
background-position:left center;  /*水平靠左 垂直居中*/
background-position:10px 50px;  /*第一个值是x 后面一个值是y*/
background-position:center 10px;
参数
length 百分数|由浮点数字和单位标识符组成的长度值
position top|center|bottom|left|center|right 方位名词

 

5.背景附着

  • 背景附着就是解释背景是滚动的还是固定的

  • 语法:

    background-attachment:scroll | fixed
参数作用
scroll 背景图像是随对象内容滚动(默认)
fixed 背景图像固定,内容动

 

6.背景简写

  • background:属性的值的书写顺序官方并没有强制标准的。为了可读性,建议大家如下写:

  • background:背景颜色 背景图片地址 背景平铺 背景滚动 背景位置;

  • 不写就是默认值,中间用空格隔开

  • 语法:

background:transparent url(image.jpg) repeat-y scroll center top;

 

7.背景透明(CSS3)

  • 语法:

background:rgba(0,0,0,0.3);
  • 最后一个参数是alpha透明度 取值范围0~1之间

  • 我们习惯把0.3的0省略掉 这样写 background:rgba(0 , 0 , 0 , .3);

  • 注意:背景半透明是指盒子背景半透明,盒子里面的内容不受影响

  • 因为是CSS3,所以低于ie9的版本是不支持的

标签:repeat,center,CSS11,url,背景,background,position
From: https://www.cnblogs.com/zjy1020/p/17253088.html

相关文章