手机上可以打html与css的app
如何使⽤HTML和CSS在图像上添加⽂字?(代码⽰例)本篇⽂章给⼤家分享的是css3中background-position的⽤法,有需要的朋友可以参考⼀下。
在css3之前设置background-position,你可以从元素的左上⾓设置位置。
例如:
1div{background-position:20px 40px;/*20px from left & 20px from top*/}
问题是⽆法从另⼀个点确定确切的位置,例如从底部/右边,我们只能从左上⾓开始。
我们可以写:background-position:right bottom;也可以写:background position:70%/从left开始/ 80%/从top开始/;,
但是我们不能从右边写20px⽽从底部写20px。
我们来看看新的background-position属性
为了解决这个问题,CSS3为我们提供了确定从何处开始定位以及确定0,0点的选项。
我们怎么实现呢?
我们现在可以⽤css3写下⽔平和垂直位置的开头,如右下⾓+起点的值,⽽不是只写2个值(左上⾓的⽔平和垂直点)。
让我们创建⼀个例⼦:
⾸先创建⼀个带有⼀些样式的空div:
HTML:
1 2<div class="box"> </div>
CSS
1 2 3 4 5 6 7 8.box{
width:300px;
height:300px;
background-color:#ddd;  padding:10px;
border:solid3px#333;  border-radius:10px;
}
现在我们将添加⼀个固定背景⼤⼩的背景图像(CSS3中的新功能)。
1 2 3 4.box{
background:url(image/cup.jpg) no-repeat;    background-size:150px150px;
}
最后我们将添加新背景位置。
⾸先我们设置⽔平起点,例如:右边和之后我们可以设置我们想要的距离,例如20px。
其次,我们设置垂直开始起点,例如:底部后,我们设定的距离,我们从该位置需要,例如40像素。CSS新背景位置
1.box{ background-position :right20px bottom40px;}
效果如下:
我们是实现了这个效果,除此之外,我们还可以实现⼀个包含多个背景图像的框,代码如下;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.box{
background-position:
left 0 top 0,
right 0 top 0,
bottom 0 right 0;
background-image:url(image/flower.jpg),  url(image/flowers.jpg),  url(image/greatwall.jpg);  background-repeat:no-repeat;
background-size:200px 200px;
width:500px;
height:500px;
background-color:#ddd;
padding:10px;
border:solid 3px #333;
border-radius:10px;
}
</style>
</head>
<body>
<div class="box">
</div>
</body>
</html>
以上就是CSS3中背景图⽚位置background-position的⽤法介绍的详细内容。

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