背景定位

背景定位

background定位只能指定距离左上角的偏移量,或者完全靠齐到其他三个角。

1、css3 background-position扩展语法方案:允许指定背景图片距离任意角的偏移量,指定偏移量前面指定的关键字。例如:

background:url(****.svg) no-repeat #58a;

background-position:right 20px bottom 10px;

在不支持background-position扩展语法的浏览器中,背景图片会紧贴在左上角。会干扰文字的可读性,提供一个回退方案也简单,就是把老套的bottom right定位值写进background的简写属性中:

background:url(****.svg) no-repeat bottom right #58a;

background-position:right 20px bottom 10px;

2、background-origin方案:让背景自动跟着设定的内边距走,不用另外声明偏移量的值。每个元素存在三个矩形框:border box、padding box、content box。默认情况下background-position是以padding box为准的,这样边框不会遮住背景图片。如果值改为content-box,在background-position属性中使用的边角关键字将会以内容区的边缘作为基准。

padding:10px;

background:url(****.svg) no-repeat bottom right #58a;

background-origin:content-box;

3、calc()方案:

background:url(****.svg) no-repeat bottom right #58a;

background-position:calc(20px) calc(10px);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值