CSS---background属性及其属性值

更新时间:2023-07-31 20:03:44 阅读: 评论:0

CSS---background属性及其属性值CSS属性:
background-color/*背景颜⾊*/
background-image/*背景图⽚*/
background-repeat/*设置背景图像是否重复,及如何重复*/
background-attachment/*背景图像是否固定或者随着页⾯的其余部分滚动*/
background-position/*设置背景图像的起始位置*/
background/*简写属性*/
1、background-color:
颜⾊值通常以以下⽅式定义:
⼗六进制 - 如:"#ff0000"
RGB - 如:“rgb(255,0,0)”
颜⾊名称 - 如:“red”
h1 {background-color:#ff0000;}
p {background-color:rgb(255,0,0);}
div {background-color:red;}牛肚多少钱一斤
2、background-image:
默认情况下,背景图像进⾏平铺重复显⽰,以覆盖整个元素实体.
body {background-image:url('background.jpg');}
提⽰:可以设置⼀种背景颜⾊,这样的话,假如背景图像不可⽤,可以使⽤背景⾊带代替。
泞泥body {
background-image:url('background.jpg');
background-color:#ffffff;
}
3、background-repeat:
常⽤属性:
repeat:背景图像将向垂直和⽔平⽅向重复。这是默认
repeat-x:只有⽔平位置会重复背景图像
repeat-y:只有垂直位置会重复背景图像
no-repeat:背景图像不会重复
例:
body
周作人作品{
background-image:url('background.jpg');
background-repeat:repeat-y;
}
4、background-position:
吸烟的害处left top:左上
修理洗衣机left center:左中
left bottom:左下
right top:右上
right center:右中
right bottom:右下
center top:居中置顶
center center:⽔平垂直居中
center bottom:居中置底
以上这些属性值,只写⼀个时,另⼀个默认为center
x% y%:x是⽔平位置,y是垂直。左上⾓是0%0%。右下⾓是100%100%。
xpos ypos:x是⽔平位置,y是垂直。左上⾓是0。单位可以是像素(0px0px)或任何其他 CSS单位以上两个属性值,只写⼀个时,另⼀个为50%
注意:使⽤该属性,background-attachment必须设置为 “fixed(固定)”.
body
{
background-image:url('background.jpg');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
4、background-attachment:
scroll: 背景图⽚随页⾯的其余部分滚动。这是默认冬至节是哪一天
fixed:背景图像是固定的
body
{
地心引力电影background-image:url('background.jpg');
background-repeat:no-repeat;
background-attachment:fixed;
}
5、background简写属性
当使⽤简写属性时,属性值的顺序为::
1.background-color
2.background-image
3. background-repeat
4. background-attachment
5. background-position
以上属性⽆需全部使⽤,你可以按照页⾯的实际需要使⽤.
胸椎痛
body {background:#ffffff url('background.jpg') no-repeat right top;}

本文发布于:2023-07-31 20:03:44,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1125050.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:背景   图像   属性   位置   垂直
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图