css3之背景定位

属性: background-position: left top || left bottom || right top || right bottom || center center || 像素值 || 百分比
实例:
代码:
 
1.设置background-position:left top 代表背景图片要放在内容区的左上角的位置(默认值)
2. 设置background-position: left; 将背景图片要放在内容区的左侧中间的位置 没有第二个参数则第二个参数默认为center
设置background-position: left bottom; 将背景图片要放在内容区的左下角的位置
3. 设置background-position: right; 将背景图片要放在内容区的右侧中间的位置,与left相同,没有第二个参数则第二个参数默认为center
4. 设置background-position: right top; 将背景图片要放在内容区的右侧上角的位置。
5. 设置background-position: right bottom; 将背景图片要放在内容区的右侧下角的位置。
6. 设置background-position: center; 将背景图片要放在内容区中间的位置。 与left, right相同,没有第二个参数则第二个参数默认为center
7. 设置background-position: 一个具体像素值(例如100px); 将背景图片要放在内容区水平位置100px的位置,即沿x轴平移100px;竖直方向默认为center即y轴居中的位置。
8. 设置background-position: 两个具体像素值(例如100px 100px); 将背景图片要放在内容区水平位置100px 垂直位置100px的位置,即沿x轴平移100px,沿y轴平移100px
9. 设置background-position: 一个百分比(例如20%); 将背景图片要放在内容区水平位置20%的位置。 0%是最左边 100%是最右边 中间平分。若只有一个值默认第二个参数为50%。
设置background-position:0%; 的效果(同left):
设置background-position:50%; 的效果(同center):
设置background-position:100%; 的效果(同right):
10. 设置background-position: 两个百分比(例如20% 20%); 将背景图片要放在内容区水平位置20%,竖直位置20% 的位置。 第一个参数:0%是最左边 100%是最右边 中间平分。第二个参数: 0%是最上边,100%是最下边 中间平分。
设置background-position:0% 100%; 的效果(同left bottom):
设置background-position:100% 100%; 的效果(同right bottom):

猜你喜欢

转载自www.cnblogs.com/pandawind/p/9791208.html