我有一个导航菜单,由 3 列组成,每列 33% 宽。在移动设备上,我希望每列都是 100% 宽并重新排列列,以便中间列位于所有其他列之上。
通过查看下面的示例,更容易看到我想要实现的目标。你知道当屏幕宽度小于 500 像素时,我如何重新排列中间列,使其位于所有其他列之上?如果有一个很棒的 css 解决方案,我相信我可以很容易地在 Javascript 中实现这一点,如果可能的话,我只是更喜欢 CSS2/CSS3 的想法。
.col-1 {
background-color: #eee;
text-align: center;
}
.col-2 {
background-color: #ccc;
text-align: center;
}
.col-3 {
background-color: #aaa;
text-align: center;
}
.title {
text-align: center;
margin-top: 75px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/2.0.3/pure-min.css">
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/grids-responsive-min.css">
<p class="title">Desktop Look</p>
<div id="menu" class="pure-g">
<div class="col-1 pure-u-1-3">
<div class="pure-menu pure-menu-horizontal custom-can-transform">
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
</ul>
</div>
</div>
<div class="col-2 pure-u-1-3">
<div class="pure-menu">
<a href="#" class="pure-menu-heading custom-brand">Brand</a>
</div>
</div>
<div class="col-3 pure-u-1-3">
<div class="pure-menu pure-menu-horizontal custom-menu-3 custom-can-transform">
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
</ul>
</div>
</div>
</div>
<p class="title"><i>Desired </i>Mobile Look</p>
<div id="menu" class="pure-g">
<div class="col-2 pure-u-1">
<div class="pure-menu">
<a href="#" class="pure-menu-heading custom-brand">Brand</a>
</div>
</div>
<div class="col-1 pure-u-1">
<div class="pure-menu pure-menu-horizontal custom-can-transform">
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
</ul>
</div>
</div>
<div class="col-3 pure-u-1">
<div class="pure-menu pure-menu-horizontal custom-menu-3 custom-can-transform">
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Link</a></li>
</ul>
</div>
</div>
</div>