本文介绍了如何在图标上方对齐徽章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在fontawesome图标上添加徽章,但它无法正确对齐.无论我尝试什么,它要么位于顶部,要么位于底部.但是我正在尝试将其添加到图标上.
I am trying to add badge over a fontawesome icon but it's not getting aligned properly. Whatever I try, it either comes in the top or on the below. But I am trying to add it over the icon.
请告诉我我想念的东西.
Please tell me what am I missing.
谢谢!
@import url('//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
.menutoggle {
float: left;
width: 50px;
height: 52px;
font-size: 22px;
cursor: pointer;
color: #1d2939;
border-right: 1px solid #eee;
border-left: 1px solid #eee;
-moz-transition: all 0.2s ease-out 0s;
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
.menutoggle i {
padding:15px;
padding-bottom:0px;
}
.menutoggle:hover {
color: #1d2939;
background-color: #f7f7f7;
}
.badge{
display:inline-block;
min-width:10px;
padding:3px 7px;
font-size:12px;
font-weight:700;
line-height:1;
color:#fff;
text-align:center;
white-space:nowrap;
vertical-align:baseline;
background-color:#777;
border-radius:10px
}
<ul>
<li>
<div class="menutoggle">
<i class="fa fa-cog"></i>
<span class="badge">1</span>
</div>
</li>
</ul>
推荐答案
您需要相对于其父 menutoggle
容器放置徽章元素.对于此设置,对于具有所需顶部和左侧/右侧值的徽章,将 position:relative;
设置为 .menutoggle
和 position:absolute;
.
You need to position badge elements relatively to their parent menutoggle
containers. For this set position: relative;
to .menutoggle
and position: absolute;
for badges with desired top and left/right values.
@import url('//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
.menutoggle {
position: relative;
float: left;
width: 50px;
height: 52px;
font-size: 22px;
cursor: pointer;
color: #1d2939;
border-right: 1px solid #eee;
border-left: 1px solid #eee;
-moz-transition: all 0.2s ease-out 0s;
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
.menutoggle i {
padding:15px;
padding-bottom:0px;
}
.menutoggle:hover {
color: #1d2939;
background-color: #f7f7f7;
}
.badge {
position: absolute;
top: 0;
right: 0;
display:inline-block;
min-width:10px;
padding:3px 7px;
font-size:12px;
font-weight:700;
line-height:1;
color:#fff;
text-align:center;
white-space:nowrap;
vertical-align:baseline;
background-color:#777;
border-radius:10px;
}
<ul>
<li>
<div class="menutoggle">
<i class="fa fa-cog"></i>
<span class="badge">1</span>
</div>
</li>
</ul>
这篇关于如何在图标上方对齐徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!