CSS转换 - 首先滑动菜单,稍后淡化文本

时间:2015-10-15 20:23:21

标签: html css3 text css-transitions fadein

所以,我正在尝试创建一个复选框,当选中菜单将淡入时,在动画结束后,文本开始淡入。 问题是,当我尝试css文本类时,它只是不会响应“已检查”的属性。

我想点击按钮,

/* 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>

1 个答案:

答案 0 :(得分:0)

因为您使用的是一般兄弟组合子(〜),所以无法直接定位.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>