CSS 背景

css中背景主要使用background标签来设置网页或区域背景(注:本文使用了超链接,如不详细可点击进入w3school学习)

1.background-color (设置网页或区域背景颜色)

  例:把p的背景设置为红色:

p {background-color: red;}

2.background-image (把图像设置为背景)

  例:把p的背景设置为map.jpg:

p {background-image: url(map.jpg;}

3.background-position (设置图像在背景中的位置

 (1)关键字:

center center center
top top center 或 center top
bottom bottom center 或 center bottom
right right center 或 center right
left left center 或 center left

 (2)百分数值:

    如果图像位于 0% 0%,其左上角将放在元素内边距区的左上角。如果图像位置是 100% 100%,会使图像的右下角放在右边距的右下角。

body
  { 
    background-image:url("map.jpg");
    background-position:50% 50%;
  }

  (3)长度值:

body
  { 
    background-image:url("map.jpg");
    background-position:50px 100px;
  }

 

 4.background-repeat (设置背景图像是否及如何重复)

repeat 默认。背景图像将在垂直方向和水平方向重复。
repeat-x 背景图像将在水平方向重复。
repeat-y 背景图像将在垂直方向重复。
no-repeat 背景图像将仅显示一次。
inherit 规定应该从父元素继承 background-repeat 属性的设置。
body
  {
  background-image: url(map.jpg);
  background-repeat: repeat-y;
  }

5.background-attachment (背景图像是否固定或者随着页面的其余部分滚动)

scroll 默认值。背景图像会随着页面其余部分的滚动而移动。
fixed 当页面的其余部分滚动时,背景图像不会移动。
inherit 规定应该从父元素继承 background-attachment 属性的设置。

  例:设置固定的背景图像:

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

 

 

posted on 2020-10-06 14:02  <ACCK>  阅读(94)  评论(0)    收藏  举报