切换按钮在我的导航栏中无效

时间:2020-08-14 20:54:08

标签: css

我不知道我的问题在哪里。实际上,当我想单击切换按钮时,没有任何反应吗?

enter image description here

通常,我必须看到替换导航栏的横幅。

enter image description here

这是横幅

enter image description here

我真的卡住了,我想知道我的问题在哪里吗?

谢谢您的帮助。

*{
    padding:0;
    margin:0;
    text-decoration: none;
    list-style: none;
    box-sizing: border-box;
}

body{
    font-family: montserrat;
}

nav{
    background: #0082e6;
    height: 80px;
    width: 100%;
}

label.logo{
    color: #fff;
    font-size: 35px;
    line-height: 80px;
    padding: 0 100px;
    font-weight: bold;
}

nav ul{
    float: right;
    margin-right: 20px;
}

nav ul li{
    display: inline-block;
    line-height: 80px;
    margin: 0 5px;
}

nav ul li a{
    color: #fff;
    font-size: 17px;
    padding: 7px 13px;
    border-radius: 3px;
    text-transform: uppercase;
}

a.active, a:hover{
    background: #1b9bff;
    transition: .5s;
}

/* hamburgeur */

.checkbtn{
    font-size: 30px;
    color: white;
    float: right;
    line-height: 80px;
    margin-right: 40px;
    display: none;
}

#check{
    display: none;
}

@media (max-width: 952px){
    label.logo{
        font-size: 30px;
        padding-left: 50px;
    }

    nav ul li a{
        font-size: 16px;
    }

}

@media (max-width: 858px){
    .checkbtn{
        display: block;
    }

    ul{
        position: fixed;
        width: 100%;
        height: 100vh;
        background: #2c3e50;
        top: 80px;
        left: 0;
        text-align: center;
        transition: all .5s;
    }

    nav ul li{
        display: block;
        margin: 50px 0;
        line-height: 30px;
    }

    nav ul li a{
        font-size: 20px;
    }

    a:hover, a.active{
        background: none;
        color: #0082e6;
    }

    #check:checked ~ ul{
        left: 0;
    }


}


section{
    background: url('https://zupimages.net/up/20/33/i8uu.jpg') no-repeat;
    background-size: cover;
    height: calc(100vh - 80px);
}
<!Doctype html>
<html lang="fr">
<head>
  <meta charset="utf-8">
  <meta charset="viewport" content="width=device-width, initial-scale=1.0">
  <title>My website</title>
  <link rel="stylesheet" href="public/css/base.css">
  <link rel="stylesheet" href="public/css/header.css">
  <link rel="stylesheet" href="style.css">
  <script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<body>

  <nav>
    <input type="checkbox" id="check">
    <label for="check" class="checkbtn">
      <i class="fas fa-bars"></i>
    </label>


    <label class="logo">Tuto</label>
    <ul>
      <li><a class="active" href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Services</a></li>
      <li><a href="#">Contact</a></li>
      <li><a href="#">Feedback</a></li>
    </ul>

  </nav>
  
  <section>
  </section>


</body>
</html>

2 个答案:

答案 0 :(得分:0)

您的切换开关不可点击,因为您已将复选框设置为display: none

改为执行此操作:

#check {
    display: block;
    width: 0;
    height: 0;
}

label[for="check"] {
    cursor: pointer;
}

答案 1 :(得分:0)

当复选框处于切换状态时,您具有相同的left值,而不是。将初始值更改为隐藏的内容,例如

@media (max-width: 858px){ ul { left: -100vw; } }