【问题标题】:Toggle Button isnt working for navigation to display html/css/js切换按钮不适用于导航以显示 html/css/js
【发布时间】:2020-10-13 12:28:57
【问题描述】:

单击导航后我的汉堡按钮不起作用应该弹出但它没有反应或做任何事情,尝试按教程自定义但它仍然不起作用 HTML

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="responsive.css">
    <!-- Bootstrap CSS-->
    <link href="script.js">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="https://kit.fontawesome.com/5599da2de4.js" crossorigin="anonymous"></script>
    <title>LAMBDA</title>
</head>
<body>
        <div class="container-fluid-full-width">
            <header>
                <div class="container">
                    <nav class="navbar m-0 p-0">
                        <div class="navbar-brand logo">
                        </div>
                        <div class="navbar-links">
                            <ul>
                                <li><a href="#">Home</a></li>
                                <li><a href="#">About</a></li>
                                <li><a href="#">Ingredients</a></li>
                                <li><a href="#">Menu</a></li>
                                <li><a href="#">Reviews</a></li>
                                <li><a href="#">Reservations</a></li>
                            </ul>
                        </div>
                        <div class="navIcons">
                            <ul>
                                <li><a href="#"><i class="fab fa-twitter"></i></a></li>
                                <li><a href="#"><i class="fab fa-youtube"></i></i></a></li>
                                <li><a href="#"><i class="fab fa-facebook-f"></i></a></li>
                            </ul>
                        </div>
                        <a href="#" class="hamburger-button">
                            <span class="bar"></span>
                            <span class="bar"></span>
                            <span class="bar"></span>
                        </a>
                    </nav>
                </div>
            </header>
        </div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="js/bootstrap.min.js"></script>
</body>
</html>

CSS

    * {
    box-sizing: border-box;
}
.nopadding {
   padding: 0 !important;
}
body {
    padding:0;
    margin:0;
}
.container-fluid {
    padding-right:0;
    padding-left:0;
    margin-right:auto;
    margin-left:auto
 }
header {
    background: url("images/headbg.png");
    display:block;
    position: relative;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    width:100%;
    height: 750px;/* baigus header nustatyti auto */
    box-shadow: inset 0px 80px 80px rgba(0, 0, 0, 0.6);
}
.logo {
    background: url("images/logo.png");
    width:161px;
    height: 99px;
}
.navbar {
    display:flex;
    justify-content: space-between;
    align-items: center;
    color:white;
}
.navbar ul {
    margin:0;
    padding:0;
    display: flex;
}
.navbar li {
    list-style: none;
}
.navbar-links {
    height: 100%;
}
.navbar-links ul li a {
    text-decoration: none;
    display: block;
    color:#fff;
    padding: 35px 20px;
    font-family: GentiumBookBasic;
    font-size:21px;
}
.navicons {
    margin:0;
    padding:0;
    text-align: left;
}
.navIcons ul li {
    list-style: none;
}
.navIconas ul li a {
    text-decoration: none;
}
.fab {
    color:#dab33e;
    margin-right:10px;
}
.navbar-links li:hover {
    box-shadow: inset 0px 3px 0px rgba(255, 255, 255, 0.8);
}
.hamburger-button {
    display: none;
    flex-direction:column;
    justify-content: space-between;
    width:30px;
    height:21px;
    position:absolute;
    top:45px;
    right:0;
}
.hamburger-button .bar {
    height: 3px;
    width: 100%;
    background-color: #fff;
    border-radius: 10px;
}
@media (max-width: 992px) {
    .hamburger-button {
        display:flex;
    }
    .navIcons {
        display: none;
    }
    .navbar {
        flex-direction: column;
    }
    .navbar-links {
        display: none;
        flex-direction:column;
        width:100%;
    }
    .navbar-links ul {
        width: 100%;
        flex-direction: column;
        align-items:flex-start;
        text-align: center;
    }
    .navbar-links ul li {
        width:100%;
        text-align: center;
    }
    .navbar-links.active {
        display: flex;
    }
}

JS

const togglebutton = document.getElementsByClassName('hamburger-button')[0]
const navbarlinks = document.getElementsByClassName('navbar-links')[0]

togglebutton.addEventListener('click', () => {
    navbarlinks.classList.toggle('active')
})`

我是新手,所以只是尝试让它工作。我是新手,所以只是尝试让它工作。 https://codepen.io/justinavii/pen/gOMaRex

【问题讨论】:

  • 请查看您的最后一段。有很多重复。

标签: javascript java html css navbar


【解决方案1】:

navbaritems

您的导航栏项目在那里,它们只是白色文本。 (#FFF)。

我更改了以下内容,它们更加明显。

.navbar-links ul li a {
    text-decoration: none;
    display: block;
    color:#01C7F5;
    padding: 35px 20px;
    font-family: GentiumBookBasic;
    font-size:21px;
}

【讨论】:

  • 因为我上传到codepen没有背景,不是这样
  • 我看了你的codepen。将屏幕最小化到启用汉堡导航栏菜单的位置。更改文本颜色后,您的菜单项现在会显示。
猜你喜欢
  • 1970-01-01
  • 2019-04-18
  • 1970-01-01
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-26
相关资源
最近更新 更多