大家好,我正在尝试做这样的事情
我需要按钮
到目前为止,我尝试使用SVG和类似这样的按钮
<div style="position:relative;">
<div style="border-radius:50px;background-color:#F3B200;border:2px solid;width:35px;height:35px;position:absolute;left:84%;margin-top:-18px;">
<center>5</center>
</div>
<div>
<button class="btn btn-success btn-lg" style="width:170px;">
<center> MYbutton</center>
</button>
</div>
</div>
但这不能以适当的方式起作用。我需要它能及时响应。
这可能是我想到的最简单的方法:
给您的按钮一个自定义data
属性。在这种情况下,我使用了data-count
(该count
部分可以是您想要的任何东西):
<button data-count="5"></button>
使用作为数据属性的值content
一个的:before
伪元件:
button:before {
content: attr(data-count);
}
完整的演示如下。
button {
background: linear-gradient(to bottom, rgba(37,130,188,1) 0%,rgba(41,137,216,1) 32%,rgba(41,137,216,1) 42%,rgba(175,224,234,1) 100%);
width: 60px;
height: 60px;
border-radius: 10px;
border: none;
margin-top: 40px;
margin-left: 40px;
position: relative;
box-shadow: 0 2px 5px rgba(0,0,0,0.4);
}
button:before {
content: attr(data-count);
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
display: block;
border-radius: 50%;
background: rgb(67, 151, 232);
border: 1px solid #FFF;
box-shadow: 0 1px 3px rgba(0,0,0,0.4);
color: #FFF;
position: absolute;
top: -7px;
left: -7px;
}
button.badge-top-right:before {
left: auto;
right: -7px;
}
button.badge-bottom-right:before {
left: auto;
top: auto;
right: -7px;
bottom: -7px;
}
button.badge-bottom-left:before {
top: auto;
bottom: -7px;
}
<button data-count="5"></button>
<button data-count="5" class="badge-top-right"></button>
<button data-count="5" class="badge-bottom-right"></button>
<button data-count="5" class="badge-bottom-left"></button>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句