本文介绍了纯CSS手机菜单:收缩时隐藏内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从 - 在折叠时如何隐藏扩展菜单?当动画内容仍然存在时,它看起来有点丑陋。
Expanding on the pure CSS morphing mobile menu from http://www.scottohara.me/article/morph-button-updated.html -- how does one hide the expanded menu while collapsing? It looks a bit ugly when the content is still present during the animation.
*, *::after, *::before {
box-sizing: border-box;
font-family: arial;
line-height: 2;
margin: 0; }
body {
background: #444;
overflow-x: hidden; }
p {
margin-bottom: 24px; }
p:last-child {
margin-bottom: 0; }
.content {
margin: auto;
max-width: 1000px;
padding: 20px; }
.invis {
height: 1px;
left: -999px;
position: absolute;
top: -999px;
visibility: hidden;
width: 1px; }
.main-base {
background: #eee;
left: 0px;
position: relative;
transition: all .3s; }
.main-base header, .main-base footer {
background: #888;
color: #fff; }
footer a {
color: #fff; }
.nav-side {
background: #56cee8;
color: #fff;
top: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
height: 60px;
left: 20px;
overflow: hidden;
padding: 8px 0;
position: fixed;
transition: all .3s;
width: 60px;
z-index: 2; }
.menu-list {
height: 0%;
list-style: none;
margin: 0;
overflow: hidden;
padding: 0;
transition: all .3s; }
.menu-list a {
border-bottom: 1px solid #eee;
color: #222;
display: block;
padding: 12px 8px;
text-decoration: none; }
.menu-list a:hover {
background: rgba(0, 0, 0, 0.5); }
.btn-label {
cursor: pointer;
display: block;
height: 60px;
width: 60px;
position: absolute;
top: 0;
left: 0; }
.btn-label .top {
height: 3px;
background-color: #fff;
position: absolute;
top: 12px;
left: 12px;
right: 12px;
}
.btn-label .middle {
height: 3px;
background-color: #fff;
position: absolute;
top: 22px;
left: 12px;
right: 12px;
}
.btn-label .bottom {
height: 3px;
background-color: #fff;
position: absolute;
top: 32px;
left: 12px;
right: 12px;
}
.btn-label .label {
text-align: center;
position: absolute;
bottom: 2px;
left: 0;
right: 0;
font-size: 12px;
}
#nav-expand:checked + .nav-side .btn-label {
display: none;
}
.close {
cursor: pointer;
text-align: right;
padding-right: 15px;
line-height: 30px;
font-size: 30px;
cursor: hand;
cursor: pointer;
display: none;
height: 40px;
border-bottom: 1px solid #fff; }
#nav-expand:checked + .nav-side .close {
display: block;
}
#nav-expand:checked + .nav-side {
bottom: 0;
height: 100%;
left: 0;
width: 200px; }
#nav-expand:checked + .nav-side .menu-list {
height: 100%; }
#nav-expand:checked + .nav-side .btn-label {
color: transparent;
display: inline-block;
height: 20px;
line-height: 20px;
text-align: center;
width: 20px; }
#nav-expand:checked + .nav-side + .main-base {
left: 200px; }
#nav-collapse + .main-base {
left: 200px; }
#nav-collapse + .main-base > .overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,.5);
opacity: 1;
transition: opacity .3s; }
#nav-collapse:checked + .main-base {
left: 0; }
#nav-collapse:checked + .main-base > .overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
height: 0;
width: 0;
opacity: 0; }
<div class="page">
<input type="radio" id="nav-expand" name="nav" class="invis" />
<nav class="nav-side">
<label for="nav-collapse" class="close">
×
</label>
<label for="nav-expand" class="btn-label">
<span class="top"></span><span class="middle"></span><span class="bottom"></span><span class="label">MENU</span>
</label>
<ul class="menu-list">
<li>
<label for="nav-collapse">
<a href="#!" title="descriptive title">
Link Label
</a>
</label>
</li>
<li>
<label for="nav-collapse">
<a href="#!" title="descriptive title">
ಠ_ಠ Link Label
</a>
</label>
</li>
</ul>
</nav>
<input type="radio" id="nav-collapse" name="nav" checked="checked" class="invis" />
<main class="main-base" role="main">
<header class="header-base" role="banner">
<div class="content">
<h1>
Display Sidebar/Settings on Click/Press of Icon
</h1>
</div>
</header>
<article>
<div class="content">
<p>
Bacon ipsum dolor sit amet filet mignon prosciutto ham hock boudin pork chop swine shoulder beef. Flank andouille ground round strip steak pork bacon venison ham hock, tongue turducken. Venison jowl hamburger salami bacon capicola. Chuck ribeye sirloin spare ribs, venison beef t-bone prosciutto swine strip steak. Chuck jowl spare ribs tenderloin prosciutto. Pancetta pork chop venison bacon short ribs porchetta. Short loin short ribs kielbasa biltong t-bone tail brisket porchetta pork pork loin chicken.
</p>
<p>
Pork belly meatball sirloin ribeye pork loin meatloaf. Tongue kielbasa chuck sausage, turducken jerky hamburger t-bone fatback frankfurter pork loin pig venison tail. Sirloin tri-tip kevin shankle salami doner jerky capicola leberkas tongue drumstick. Tongue turkey prosciutto salami tri-tip. Shank doner sirloin landjaeger pancetta beef ribs.
</p>
<p>
Frankfurter pork loin short ribs andouille kevin. T-bone tail pig chuck prosciutto brisket. Landjaeger tail fatback beef porchetta, biltong shoulder turkey shankle kevin jowl pancetta brisket pork belly boudin. Short loin tenderloin swine, hamburger bresaola rump shank ground round ham kielbasa chicken pancetta capicola. Boudin chicken frankfurter, pig kielbasa flank ball tip. Corned beef pastrami landjaeger, meatloaf flank shankle pig meatball chuck pork loin swine.
</p>
<p>
Pork belly meatball sirloin ribeye pork loin meatloaf. Tongue kielbasa chuck sausage, turducken jerky hamburger t-bone fatback frankfurter pork loin pig venison tail. Sirloin tri-tip kevin shankle salami doner jerky capicola leberkas tongue drumstick. Tongue turkey prosciutto salami tri-tip. Shank doner sirloin landjaeger pancetta beef ribs.
</p>
<p>
Frankfurter pork loin short ribs andouille kevin. T-bone tail pig chuck prosciutto brisket. Landjaeger tail fatback beef porchetta, biltong shoulder turkey shankle kevin jowl pancetta brisket pork belly boudin. Short loin tenderloin swine, hamburger bresaola rump shank ground round ham kielbasa chicken pancetta capicola. Boudin chicken frankfurter, pig kielbasa flank ball tip. Corned beef pastrami landjaeger, meatloaf flank shankle pig meatball chuck pork loin swine.
</p>
</div>
</article>
<footer>
<div class="content">
<p>
oh bai
</p>
</div>
</footer>
<label for="nav-collapse" class="overlay"></label>
</main>
</div>
推荐答案
p>您可以在菜单项上添加一些转换,使它们更顺利地消失。
You can maybe add some transition on the menu items to make them disappear more smoothly.
我做了一些测试@
.menu-list a {
margin-left: -200px;
transition: margin-left .3s;
}
#nav-expand:target .menu-list a {
margin-left: 0;
}
远离完美,但它改善了动画。
Far from perfect but it does improve the animation.
(请注意,它基于您的其他问题的修改代码()
(Note that it's based on the modified code for your other question (Pure CSS mobile menu: Unable to close)
这篇关于纯CSS手机菜单:收缩时隐藏内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!