【发布时间】:2022-01-20 18:03:42
【问题描述】:
当页面宽度缩小时,我试图通过媒体查询更改导航栏列表的显示。我在列表之间添加了填充,但它并没有以某种方式出现。我想知道是不是因为 flexbox 或其他原因。
HTML 代码
<header id="header">
<h1><img id="header-img" src="https://cdn-icons-png.flaticon.com/512/4907/4907546.png" alt="cat tower">Aristocat Tower</h1>
<nav id="nav-bar">
<ul id="nav-list">
<li><a class="nav-link" href="#features">Features</a></li>
<li><a class="nav-link" href="#howItWorks">How It Works</a></li>
<li><a class="nav-link" href="#pricing">Pricing</a></li>
</ul>
</nav>
</header>
CSS 代码
#header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
#nav-list {
list-style: none;
display: flex;
flex-direction: row;
}
.nav-link {
margin: 1em 1em;
}
@media (max-width: 750px) {
#header {
display: flex;
flex-direction: column;
align-items: center;
}
#nav-list {
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
}
.nav-link {
padding: 5px;
}
}
【问题讨论】: