如果我将导航栏中的图标与display: flex
对齐,则会在我的图标下方显示下划线。如果我禁用它,它们会消失但我的图标不能正确对齐。见下图。
我怎样摆脱它们?
以下是代码:
.nav {
width: 60px;
height: 100vh;
top: 100px;
min-height: 100vh;
background-color: #cccccc;
position: fixed;
z-index: 999;
opacity: .4;
border-right: 1px solid black;
display: flex;
flex-direction: column;
}
.nav a {
width: 100%;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
border: none;
}

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="nav">
<a href=""><i class="material-icons">home</i></a>
<a href=""><i class="material-icons">shopping_basket</i></a>
<a href=""><i class="material-icons">business</i></a>
<a href=""><i class="material-icons">mail</i></a>
<a href=""><i class="material-icons">card_giftcard</i></a>
</div>
&#13;
答案 0 :(得分:5)
<a>
代码标记text-decoration:underline
,这就是为什么该行会在下面显示。
将text-decoration: none
应用于您的主播代码.nav a
Stack Snippet
.nav {
width: 60px;
height: 100vh;
top: 100px;
min-height: 100vh;
background-color: #cccccc;
position: fixed;
z-index: 999;
opacity: .4;
border-right: 1px solid black;
display: flex;
flex-direction: column;
}
.nav a {
width: 100%;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
border: none;
text-decoration: none;
}
&#13;
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="nav">
<a href=""><i class="material-icons">home</i></a>
<a href=""><i class="material-icons">shopping_basket</i></a>
<a href=""><i class="material-icons">business</i></a>
<a href=""><i class="material-icons">mail</i></a>
<a href=""><i class="material-icons">card_giftcard</i></a>
</div>
&#13;
答案 1 :(得分:3)
在添加display: flex
之前没有下划线的原因是因为<i>
设置为display: inline-block
,下划线不会为其呈现。
添加display: flex
后,display: inline-block
上的<i>
将不再适用,因为flex项目阻止元素。
将text-decoration: none
添加到a
将解决此问题
由于a
具有固定的高度,因此可以选择放弃display: flex
并使用text-align
/ line-height
将图标置于中心位置。
.nav {
width: 60px;
height: 100vh;
top: 100px;
min-height: 100vh;
background-color: #cccccc;
position: fixed;
z-index: 999;
opacity: .4;
border-right: 1px solid black;
display: flex;
flex-direction: column;
}
.nav a {
width: 100%;
height: 60px;
border: none;
text-align: center;
}
.nav a i {
line-height: 60px;
}
&#13;
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="nav">
<a href=""><i class="material-icons">home</i></a>
<a href=""><i class="material-icons">shopping_basket</i></a>
<a href=""><i class="material-icons">business</i></a>
<a href=""><i class="material-icons">mail</i></a>
<a href=""><i class="material-icons">card_giftcard</i></a>
</div>
&#13;
答案 2 :(得分:1)
尝试使用text-decoration: none;
作为链接