gpt4 book ai didi

html - 如何在图标上放置通知徽章?

转载 作者:行者123 更新时间:2023-12-04 10:35:56 25 4
gpt4 key购买 nike

我正在尝试让通知徽章正常工作,我快到了:)

当我在那里有通知徽章时它工作得很好,但如果我删除它,图标会由于某种原因下降,我不知道为什么。

enter image description here

.icon-badge-group .icon-badge-container {
display: inline-block;
margin-left: 15px;
}

.icon-badge-group .icon-badge-container:first-child {
margin-left: 0
}

.icon-badge-container {
margin-top: 20px;
position: relative;
}

.icon-badge-icon {
font-size: 30px;
position: relative;
}

.icon-badge {
background-color: red;
font-size: 12px;
color: white;
text-align: center;
width: 20px;
height: 20px;
border-radius: 35%;
position: relative;
top: -35px;
left: 17px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" rel="stylesheet"/>
<div class="container">
<div class="icon-badge-container">
<i class="far fa-envelope icon-badge-icon"></i>
<div class="icon-badge">6</div>
</div>
<div class="icon-badge-container">
<i class="far fa-user icon-badge-icon"></i>
<div class="icon-badge">6</div>
</div>

<div class="icon-badge-group">
<div class="icon-badge-container">
<i class="far fa-envelope-open icon-badge-icon"></i>
<div class="icon-badge">6</div>
</div>
<div class="icon-badge-container">
<i class="far fa-user icon-badge-icon"></i>
</div>
<div class="icon-badge-container">
<i class="far fa-user icon-badge-icon"></i>
<div class="icon-badge">6</div>
</div>
</div>

最佳答案

你做得很好,唯一需要改变的是 relative 的位置至absolute .更改此选项时,徽章将停止与其他元素流/布局位置交互,并将成为您的 icon-badge-container 的一种“顶层”元素。

另一个 inline-block 元素 icon-badge-container不会再被你的徽章打扰了。

我用注释标记了 CSS 更改了哪些行。

更多职位信息:https://developer.mozilla.org/en-US/docs/Web/CSS/position

.icon-badge-group {

}

.icon-badge-group .icon-badge-container {
display: inline-block;
margin-left:15px;
}

.icon-badge-group .icon-badge-container:first-child {
margin-left:0
}

.icon-badge-container {
margin-top:20px;
position:relative;
}

.icon-badge-icon {
font-size: 30px;
position: relative;
}

.icon-badge {
background-color: red;
font-size: 12px;
color: white;
text-align: center;
width:20px;
height:20px;
border-radius: 35%;
position: absolute; /* changed */
top: -5px; /* changed */
left: 18px; /* changed */
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">


<div class="icon-badge-group">
<div class="icon-badge-container">
<i class="far fa-envelope-open icon-badge-icon"></i>
<div class="icon-badge">6</div>
</div>
<div class="icon-badge-container">
<i class="far fa-user icon-badge-icon"></i>
</div>
<div class="icon-badge-container">
<i class="far fa-user icon-badge-icon"></i>
<div class="icon-badge">6</div>
</div>
</div>

关于html - 如何在图标上放置通知徽章?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60186557/

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