gpt4 book ai didi

html - 使用 html 和 CSS 的按钮徽章

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:08 24 4
gpt4 key购买 nike

大家好,我正在尝试做这样的事情

enter image description here

我需要它做按钮

到目前为止,我尝试使用 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>

使用 data 属性的值作为 :before 伪元素的 content:

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>

关于html - 使用 html 和 CSS 的按钮徽章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27015025/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com