CSS过渡-先滑动菜单,后淡出文本



所以,我试图使一个复选框,当选中一个菜单将淡入,动画完成后,文本开始淡入。问题是,当我尝试css文本类,它只是不会响应"checked"属性。

我想点击按钮,

/* MENU */
.nav-a {
    display: block;
    text-align: center;
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.4s 1s;
}
input[type=checkbox]:checked ~ .nav-a {
    opacity: 1;
}
#nav-li {
    float: right;
    display: inline-block;
    height: 50px;
    line-height: 50px;
    width: 100px;
}
#nav-ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
#nav {
    background-color: #707068;
    position: absolute;
    top: 0;
    width: 250px;
    height: 50px;
    z-index: -1;
    opacity: 0;
    transition: opacity 1s, transform 1s;
}
input[type=checkbox]:checked ~ #nav {
   opacity: 1;
}
/* BOTAO MENU */
input[type=checkbox] {
   position: absolute;
   opacity: 0;
}
label {
   position: absolute;
   z-index: 1;
    font-family:monospace;
   font-size: 60px;
    line-height: 38px;
    height: 30px;
    width: 30px;
   color: #707068;
   cursor: pointer;
    left: 10px;
    
}
input[type=checkbox]:checked ~ label {
   color: #9a9a8d;
}
<div id="wrapper-menu">
  <input id="menu" type="checkbox"><label for="menu">&equiv;</label>
  <nav id="nav">
      <ul id="nav-ul">
          <li id="nav-li"><a class="nav-a" href="">projetos</a></li>
          <li id="nav-li"><a class="nav-a" href="">perfil</a></li>
      </ul>
  </nav>
</div>

因为您使用的是一般的兄弟组合子(~),所以您不能直接针对.nav-a。您需要针对它的父节点,即复选框的兄弟节点,如#nav

/* MENU */
.nav-a {
    display: block;
    text-align: center;
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.4s 1s;
}
input[type=checkbox]:checked ~ #nav .nav-a {
    opacity: 1;
}
#nav-li {
    float: right;
    display: inline-block;
    height: 50px;
    line-height: 50px;
    width: 100px;
}
#nav-ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
#nav {
    background-color: #707068;
    position: absolute;
    top: 0;
    width: 250px;
    height: 50px;
    z-index: -1;
    opacity: 0;
    transition: opacity 1s, transform 1s;
}
input[type=checkbox]:checked ~ #nav {
   opacity: 1;
}
/* BOTAO MENU */
input[type=checkbox] {
   position: absolute;
   opacity: 0;
}
label {
   position: absolute;
   z-index: 1;
    font-family:monospace;
   font-size: 60px;
    line-height: 38px;
    height: 30px;
    width: 30px;
   color: #707068;
   cursor: pointer;
    left: 10px;
    
}
input[type=checkbox]:checked ~ label {
   color: #9a9a8d;
}
<div id="wrapper-menu">
  <input id="menu" type="checkbox"><label for="menu">&equiv;</label>
  <nav id="nav">
      <ul id="nav-ul">
          <li id="nav-li"><a class="nav-a" href="">projetos</a></li>
          <li id="nav-li"><a class="nav-a" href="">perfil</a></li>
      </ul>
  </nav>
</div>

相关内容

  • 没有找到相关文章

最新更新