CSS background-position 属性

background-position 属性设置背景图像的起始位置。

语法:

background-position : length || length 
background-position : position || position 

取值: 
length  :百分数 | 由浮点数字和单位标识符组成的长度值
position  : top | center | bottom | left | center | right 

1、background-position没有设置时,默认是background-position:0 0:

该效果background-position:left top;和background-position:0% 0%;是一致的

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        div{
            width:400px;
            height:300px;
            background:transparent url(images/img5.jpg) no-repeat;
            border:5px solid green;
        }
    </style>
</head>
<body>
<div></div>
</body>
</html>

  图片如下:

2、background-position设置具体值,第一个值表示x轴移动量,第二个值表示y轴移动量:

div{
            width:400px;
            height:300px;
            background:transparent url(images/img5.jpg) no-repeat;
            border:5px solid green;
            background-position:70px 40px;//图片向右移动70px,向下移动了40px,如果图片要向左或者向上,可以设负值background-position:-70px -40px 
}

  如图:

3.background-position:center center或者background-position:50% 50%;设置背景居中

div{
            width:400px;
            height:300px;
            background:transparent url(images/img5.jpg) no-repeat;
            border:5px solid green;
            /*background-position:center center;*/
            background-position:50% 50%;
        }

如图:  

 

转载于:https://www.cnblogs.com/yttbbd/p/4842939.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值