【发布时间】:2019-08-14 10:52:15
【问题描述】:
我希望我的导航 <li> 项目能够像现在一样彼此并排。但是当屏幕尺寸为 545 像素或更小时,我希望它们彼此重叠(1 列)。
导航在达到 545 像素时不会变为 1 列。
我已尝试添加flex-direction: column
到@media(max-width: 545px)
给nav ul
nav {
padding-left: 0px;
}
nav ul {
display: flex;
}
nav ul li {
list-style: none;
margin-right: 50px;
}
nav ul li a {
color: #8B8B8B;
text-decoration: none;
font-weight: bold;
font-size: 17px;
text-align: center;
}
nav ul li a:hover {
color: #56B8AE;
border-bottom: 1px solid;
/* I WANT A ONE ROW STACK OF THE NAV ONCE THE SCREEN IS 545px or SMALLER */
@media (max-width: 545px) {
nav {
padding-top: 0;
padding-bottom: 30px;
margin-top: 0;
min-height: 100px;
text-align: center;
}
nav ul {
flex-direction: column;
}
nav ul li {
border-top: solid 1px #e6ecf0;
padding-bottom: 5px;
}
<head>
<link rel="stylesheet" href="style.css">
</head>
<header>
<nav>
<ul class="top-nav">
<li class="top-nav-links"><a href="#"><i class="fas fa-home"></i> Home</a></li>
<li class="top-nav-links"><a href="#"><i class="fas fa-store"></i> Shop</a></li>
<li class="top-nav-links"><a href="#"><i class="fas fa-music"></i> Music</a></li>
</ul>
</nav>
<header>
我希望它变成 545 像素或更少的一列。但它会保留为一排。
【问题讨论】:
标签: html css flexbox media-queries responsive