background 属性及遇到的问题

所有属性

说明CSS
background-color 指定要使用的背景颜色 1
background-position 指定背景图像的位置 1
background-size 指定背景图片的大小 3
background-repeat 指定如何重复背景图像 1
background-origin 指定背景图像的定位区域 3
background-clip 指定背景图像的绘画区域 3
background-attachment 设置背景图像是否固定或者随着页面的其余部分滚动。 1
background-image 指定要使用的一个或多个背景图像 1

综合属性


// 综合属性

body{ background: #00FF00 url(bgimage.gif) no
-repeat left center fixed; } // 对应属性 body{ background-color: #00FF00; background-image: url(bgimage.gif); background-repeat: no-repeat;// 默认 repeat,除此之外:repeat-x 、repeat-y background-position: left center;// 分别代表,横向:left 、center 、right 、10px ,纵向:top 、center 、bottom 、10px background-attachment: fixed; }
// 其他属性使用举例
{
  background-size: auto 100%; // 100% 100% 充满,auto 自适应
  background-origin: padding-box;
}

background-origin:

  • background-origin: padding-box // 背景图像相对于内边距框来定位。
  • background-origin: border-box // 背景图像相对于边框盒来定位。
  • background-origin: content-box // 背景图像相对于内容框来定位。

注释:如果背景图像的 background-attachment 属性为 "fixed",则该属性没有效果。background-origin 属性规定 background-position 属性相对于什么位置来定位。

设置background有白色边框

因为没有给img标签这是src,所以浏览器当做没有图片处理,给加上了白色边框,解决方法有两个: 
  1.添加一个空白图,或者设置 src="#"(#可以是任何值,代表一个空链接); 
  2.不用img标签,用span、div等等

posted @ 2020-05-06 10:56  真的想不出来  阅读(407)  评论(0编辑  收藏  举报