1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 前端开发_HTML5_CSS部分-背景(background)

前端开发_HTML5_CSS部分-背景(background)

时间:2019-01-11 22:47:16

相关推荐

前端开发_HTML5_CSS部分-背景(background)

背景(background)

1.引入

为了更好对内容有更好的颜色搭配和设置,我们可以使用背景做一些美化效果,那么接下来我们一起学习以下背景相关的属性。

2.背景(background)相关的属性样式

背景(background)相关的样式属性1.background-color:设置元素的背景颜色,可以使用关键字,也可以使用HEX和RGB2.background-image:设置背景图片3.background-repeat:设置背景图片的重复方式,其参数值和参数值的含义如下:repeat:默认值,表示背景图像会在x轴方向和y轴方向平铺。no-repeat:表示不平铺,仅仅单独现实当前图片大小信息。repeat-x:表示在x轴上平铺repeat-y:表示在y轴上平铺4.background-position:设置元素的背景图片位置,其位置关系可以使用三个方式来指定。关键字:left、center、right、top、bottom百分比:百分比一般需要指定两个方向上的内容,分别为水平方向,如:50%垂直方向, 如:50%像素值:基于坐标原点水平偏移量和垂直偏移量5.background-size:设置元素背景图片的大小6.background:设置背景的复合属性

3.背景相关代码示例以及效果截图

<style type="text/css">body{font-family: '宋体';font-size: 18px;color: white;}.box1 {width: 150px;height: 150px;background-color: green;}.box2{width: 380px;height: 340px;background-image: url(images/2.jpg);}.box3{width: 380px;height: 340px;background-image: url(images/2.jpg);background-repeat: no-repeat;}.box4{background-color: aqua;width: 380px;height: 340px;background-image: url(images/2.jpg);background-repeat: no-repeat;background-position: 50% 50%;background-size: 180px 180px;}</style><body><div class="box1">设置背景颜色</div><div class="box2">设置背景图</div><div class="box3">设置背景图重复方式(演示不重复)</div><div class="box4">设置背景图片的位置 + 大小</div></body>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。