CSS Background

http://www.runoob.com/css/css-background.html

http://www.w3school.com.cn/css/css_background.asp

CSS 背景属性用于定义HTML元素的背景。

CSS 属性定义背景效果:

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position

背景颜色

background-color 属性定义了元素的背景颜色.

CSS中,颜色值通常以以下方式定义:

  • 十六进制 - 如:"#ff0000"
  • RGB - 如:"rgb(255,0,0)"
  • 颜色名称 - 如:"red"
body {background-color:#b0c4de;}
h1 {background-color:#6495ed;}
p {background-color:#e0ffff;}
div {background-color:#b0c4de;}

 

背景图像

background-image 属性描述了元素的背景图像.

默认情况下,背景图像进行平铺重复显示,以覆盖整个元素实体.

body {background-image:url('paper.gif');}

 

 

背景图像 - 水平或垂直平铺

默认情况下 background-image 属性会在页面的水平或者垂直方向平铺。

background-repeat:repeat-x;    //只在横轴方向重复

background-repeat:repeat-y;    //只在纵轴方向重复

background-repeat:repeat;       //默认的应该是这个,横轴和纵轴方向都进行重复

background-repeat:no-repeat;   //不重复

background-repeat:space;          //横轴和纵轴方向都重复,但是图片重复的时候,会加空格。最后形成网状的效果

 

背景图像- 设置定位与不平铺

background-repeat:no-repeat;
background-position:right top;

 

背景- 简写属性

为了简化这些属性的代码,我们可以将这些属性合并在同一个属性中.

背景颜色的简写属性为 "background":

body {background:#ffffff url('img_tree.png') no-repeat right top;}

当使用简写属性时,属性值的顺序为::

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position

以上属性无需全部使用,你可以按照页面的实际需要使用.

 

如何设置固定的背景图像

background-attachment:fixed;

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(244)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示