如何在购物车图标的右上角放置数字?

时间:2018-07-12 11:12:42

标签: html css font-awesome

我想在真棒购物车图标的右上角放置一个数字。

我创建了这个简单的html。

Tube tube = Tube.getInstance();
Fraction fraction = tube.fractions.get(tube.fractions.size() - 1);
Line line = fraction.lines.get(tube.fractions.size() - 1);

结果如下。

enter image description here

如何使数字显示在购物车图标的右上角,如下图所示?

enter image description here

我非常感谢CSS专家的任何帮助。谢谢!

4 个答案:

答案 0 :(得分:2)

以前似乎已经回答过: Shopping cart - number of items in cart CSS

修改了代码以适合您的要求: http://jsfiddle.net/LhrLe0j6/361/

<i class="fa" style="font-size:24px">&#xf07a;</i>
<span class='badge badge-warning' id='lblCartCount'> 5 </span>

CSS:

.badge {
  padding-left: 9px;
  padding-right: 9px;
  -webkit-border-radius: 9px;
  -moz-border-radius: 9px;
  border-radius: 9px;
}

.label-warning[href],
.badge-warning[href] {
  background-color: #c67605;
}
#lblCartCount {
    font-size: 12px;
    background: #ff0000;
    color: #fff;
    padding: 0 5px;
    vertical-align: top;
    margin-left: -10px; 
}

答案 1 :(得分:2)

使用相同的i标签的伪元素,无需额外的span标签就可以实现相同的目的。可以在相应图标的value属性中指定该值。

.badge:after{
content:attr(value);
font-size:12px;
background: red;
border-radius:50%;
padding:3px;
position:relative;
left:-8px;
top:-10px;
opacity:0.9;
}
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  

    <i class="fa badge" style="font-size:24px" value=5>&#xf07a;</i>

答案 2 :(得分:1)

使用这样的div扭曲元素,

<style>

.wrapper{
position: relative;
}
.wrapper span{
position: absolute;
top: -2px;
right: -2px; 
}

</style>

<body>

<div class="wrapper">
<i class="fa" style="font-size:24px">&#xf07a;</i>
<span> 5 </span>
</div>

</body>

答案 3 :(得分:0)

span{
    font-size: 14px;
    font-weight: 900;
    position: absolute;
    border: solid blue;
    border-radius: 60%;
    height: 14px;
    width: 8px;
    background:blue;
}
<!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    </head>
    <body>

    <i class="fa" style="font-size:24px">&#xf07a;</i>
    <span> 5 </span>

    </body>
    </html>

相关问题