CSS样式-背景(background)

CSS样式

css背景(background)

CSS 可以添加背景颜色和背景图片, 以及来进行图片设置。

属性
background-color 背景颜色
background-image 背景图片地址
background-repeat 是否平铺
background-postion 背景位置
background-attachment 背景固定还是滚动

背景图片(image)

语法:

background-image: none|url(图片地址)

参数:

  • none :  无背景图(默认的)
  • url :  使用绝对或相对地址指定背景图像
/* 示列 */
body {background-image: url(/i/eg_bg_04.gif);}
  • url()中的图片地址可以不加引号
  • 可以和 background-color连起来使用, 图片没有覆盖的位置会使用color来填充

背景平铺(repeat)

语法:

background-repeat : repeat | no-repeat | repeat-x | repeat-y

  • repeat :  背景图像在纵向和横向上平铺(默认)
  • no-repeat :  背景图像不平铺
  • repeat-x :  背景图像在横向上平铺
  • repeat-y :  背景图像在纵向平铺
/*示列*/
body {
    background-image: url(/i/eg_bg_03.gif);
    background-repeat: repeat-y;
}

背景位置(position)

语法:

/* 使用百分比或者具体长度值指定图像位置 */
background-position : length || length
/* 或者使用方位名词来指定图像位置 */
background-position : position || position

参数:

  • length : 百分数 | 由浮点数字和单位标识符组成的长度值
  • position :  top | center | bottom | left | center | right
/*示列*/
body {
    background-image: url(/i/eg_bg_03.gif);
    background-position: 15px top;
}

背景附着(attachment)

语法:

background-attachment : scroll | fixed

参数:

  • scroll : 背景图像是随对象内容滚动(默认)
  • fixed : 背景图像固定
/*示列*/
body {
    background-image: url(/i/eg_bg_03.gif);
    background-position: 15px top;
    background-attachment : fixed;
}

背景简写

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

/*示列*/
body {
    background: transparent url(image.jpg) repeat-y  scroll 50% 0 ;
}

CSS3中颜色值可以使用 background: rgba(0,0,0,0.2);

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 28,079评论 1 45
  • Div和Span标签 什么是div? 作用: 一般用于配合css完成网页的基本布局 什么是span? 作用: 一般...
    Jackson_yee_阅读 4,318评论 1 1
  • 背景颜色 如何设置标签的背景颜色?在CSS中有一个background-color:属性, 就是专门用来设置标签的...
    喝酸奶要舔盖__阅读 4,143评论 0 0
  • background-color background-color:#ff0000红色background-col...
    每日活菌阅读 3,440评论 0 0
  • 孩子们终于都睡着了。儿子臀部的脓包已经好几个月了 到今天反而严重了,他不爱吃中药,平时吃饭又喜欢辛辣和甜食,...
    漫漫来lily阅读 929评论 2 7