纯CSS移动菜单:收缩时隐藏内容

Pure CSS mobile menu: Hiding content while contracting

http://www.scottohara.me/article/morph-button-updated.html 的纯 CSS 变形移动菜单上展开 -- 如何在折叠时隐藏展开的菜单? 看起来有点丑当内容在动画期间仍然存在时。

http://codepen.io/anon/pen/PwEBaM

 *, *::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">
        &times;
      </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>

您或许可以在菜单项上添加一些过渡效果,使它们消失得更顺畅。

我做了一些测试@http://codepen.io/manuszep/pen/NPyWqV

.menu-list a {
    margin-left: -200px;
    transition: margin-left .3s;
}

#nav-expand:target .menu-list a {
    margin-left: 0;
}

远非完美,但确实改进了动画效果。

(请注意,它是基于您其他问题的修改代码()