我想在我的网站上制作一个菜单,下面会有一个带有文字的图标,当我添加文字时,它会向右移动并推送结束FactDetail.FactHeaderKey
带有图标但没有文字的导航栏
带文字的导航栏(推送最后一段李)
<li>
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css');
.adminNavigation {
width: 100%;
height: 80px;
background-color: #ebebeb;
border-radius: 3px;
}
.adminNavOptions {
display: table;
margin: 0 auto;
line-height: 80px;
}
.adminNavOptions li {
display: inline-block;
padding-right: 62px;
padding-left: 62px;
}
.adminNavOptions li:hover {
background-color: #000;
}
编辑 - 添加Gleb Kemarsky的代码后,它看起来像这样 - 图标不是垂直居中的,图标需要以文字为中心,所以
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="adminNavigation">
<ul class="adminNavOptions">
<li><i class="fa fa-play fa-3x"></i> test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</div>
</div>
答案 0 :(得分:1)
试试这个:
<强> .adminNavigation 强>
display: table;
。padding-left
属性指定零值。.adminNavOptions li
display: block; float: left;
代替display: inline-block;
。text-align: center; width: 16.66666667%;
代替padding-right: 62px; padding-left: 62px;
。图标强>
<li>
的内容由line-height
属性垂直对齐。因此,如果您需要在文本上方放置一个图标,则还需要更改<li>
的属性。为此,我添加了.iconAbove
类。position: relative; top: 9px;
调整图标的垂直位置。<强>:悬停强>
border-radius
和最后一个设置<li>
属性。请检查结果:
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css');
.adminNavigation {
height: 80px;
background-color: #ebebeb;
border-radius: 3px;
}
.adminNavOptions {
margin: 0;
line-height: 80px;
padding-left: 0;
}
.adminNavOptions .fa {
position: relative;
top: 9px;
}
.adminNavOptions .iconAbove {
height: 80px;
line-height: normal;
padding-top: 11px;
}
.adminNavOptions .iconAbove .fa {
display: block;
position: static;
}
.adminNavOptions li {
display: block;
float: left;
text-align: center;
width: 16.66666667%;
}
.adminNavOptions li:hover {
background-color: #000;
color: #fff;
}
.adminNavOptions li:first-child:hover {
border-radius: 3px 0 0 3px;
}
.adminNavOptions li:last-child:hover {
border-radius: 0 3px 3px 0;
}
<div class="col-md-offset-3 col-md-6">
<div class="adminNavigation">
<ul class="adminNavOptions">
<li class="iconAbove"><i class="fa fa-play fa-3x"></i> test</li>
<li><i class="fa fa-play fa-3x"></i> test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</div>
</div>