css效果积累02

8 篇文章 0 订阅
通过background-position来设置图片显示的具体位置

首先放代码

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.car {
    width: 120px;
    height: 30px;
    background: url(./car.png) no-repeat -17px 7px blue;
    border: 1px solid #eee;
    padding-left: 30px;
    position: relative;
    _padding-top: 5px;
    _height: 25px;
}

.car span {
    background-image:url(./car.png);
    background-position:left -36px top -54px;
    padding-left: 7px;
    position: absolute;
    top: -12px;
    left: 20px;
}

.car span i {
    float: left;
    height: 20px;
    background-image:url(./car.png);
    background-position:right -25px;
    padding-right: 5px;
    font-style: normal;
    color: black;
    font-size: 14px;
}

.car a {
    color: #aaa;
    text-decoration: none;
    font-size: 14px;
    padding-left: 15px;
    line-height: 30px;
}

.car b {
    display: inline-block;
    border-color: transparent transparent transparent #CCCCCC;
    border-style: dashed dashed dashed solid;
    border-width: 5px;
    height: 0;
    overflow: hidden;
    width: 0;
}
</style>
</head>
<body>
    <br />
    <br />
    <div class="car">
        <span><i>155</i></span> <a href="NewFile.html" target="_blank">去购物车结算</a>
        <b></b>
    </div>
</body>
</html>

实现效果如下图:这里写图片描述


原图在这里:这里写图片描述


解释下主要实现的参数background-position,这个属性可以设置背景图片的具体显示位置,left表示图片左移动多少,top表示图片上移动多少,如果是负数,则表示相反方向移动,如left -54px,其实就是向右移动54px。这样我们可以通过调节具体的数值,通过调节绝对位置,来做到上面的效果。注意,这里的left,top等这些属性,是对背景图片本身来说的。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值