我试图使以下自定义导航栏响应。我只使用div块创建它,因为它对我来说更容易理解,代码更短,更简单,而且是纯CSS。下面是Codepen的链接:https://codepen.io/familias/pen/WNYraNy。
下面是CSS:
.table-cell {
display: table-cell;
margin: 0;
padding: 0;
border: 0;
outline: 0;
border-spacing: 0;
border-collapse: collapse;
width: 100%;
}
.superior {
position: relative;
display: inline-block;
}
.superior a {
position: relative;
display: inline-block;
margin: none;
padding: none;
border: none;
outline: none;
font-size: 16px;
color: #000000;
text-transform: uppercase;
text-decoration: none;
height: 30px;
line-height: 30px;
text-align: center;
padding: 8px 20px 8px 20px;
}
.superior a:hover {
text-decoration: none;
color: #e5633f;
font-weight: 400;
}
.inferior {
display: none;
position: absolute;
width: auto;
left: 50%;
transform: translateX(-50%);
text-align: center;
white-space: nowrap;
border-left: 1px solid #000;
border-right: 1px solid #000;
border-bottom: 0px solid #000;
}
.inferior a {
margin: none;
padding: none;
border: none;
outline: none;
display: block;
font-size: 14px;
font-weight: 400;
padding-right: 30px;
padding-left: 30px;
color: #000000;
text-transform: uppercase;
text-decoration: none;
height: 20px;
line-height: 20px;
text-align: center;
border-bottom: 1px solid #000;
}
.inferior a:hover {
font-weight: 400;
text-decoration: none;
color: #fff;
background-color: #000;
}
.superior:hover .inferior {
display: block;
}
<div id="table">
<div id="table-row">
<div class="table-cell">
<div class="superior"><a href="#">News</a>
<div class="inferior">
<a href="#">This is the first link</a>
<a href="#">This is the second link</a>
</div>
</div>
<div class="superior"><a href="#">Politics</a>
<div class="inferior">
<a href="#">This is the first link</a>
<a href="#">This is the second link</a>
</div>
</div>
<div class="superior">
<a href="#">Economy</a>
<div class="inferior">
<a href="#">This is the first link</a>
<a href="#">This is the second link</a>
</div>
</div>
<div class="superior"><a href="#">Culture</a>
<div class="inferior">
<a href="#">This is the first link</a>
<a href="#">This is the second link</a>
</div>
</div>
<div class="superior"><a href="#">Health</a>
<div class="inferior">
<a href="#">This is the first link</a>
<a href="#">This is the second link</a>
</div>
</div>
<div class="superior"><a href="#">Education</a>
<div class="inferior">
<a href="#">This is the first link</a>
<a href="#">This is the second link</a>
</div>
</div>
<div class="superior"><a href="#">Live</a>
<div class="inferior">
<a href="#">This is the first link</a>
<a href="#">This is the second link</a>
</div>
</div>
</div>
</div>
</div>
我需要的是菜单垂直显示时,在移动的上查看。我如何才能做到这一点?
2条答案
按热度按时间eivgtgni1#
您可以尝试这样做,“@media only screen和(max-width:600 px)”意味着只有当特定条件为真时才包括CSS属性块,在这种情况下,如果屏幕小于600 px。它将创建垂直菜单,你可以添加样式,你需要。
dsekswqp2#
下面是一个使用网格样式的选项,带有汉堡菜单的复选框标签:超级丑陋,但只是为了显示什么是在哪里。注意菜单上的悬停显示了相关的
.inferior
,但这可能更花哨;更多的只是功能在这里比超级漂亮只是为了展示它如何可以做到。