Error with adaptable menu

I am attempting to develop a responsive menu similar to the Bootstrap nav bar using only CSS. I have managed to get the functionality working, but the positioning of the menu grabber is incorrect and I'm unsure how to correct it. The grabber should align with the logo text, and the red box should only appear below the black bar along with the items.

HTML:

<div id="wrapper">
    <div id="header" class="clearfix">
        <span class="logo">Logo</span>

        <input type="checkbox" id="navbar-checkbox" class="navbar-checkbox">
        <nav class="nav-menu">
            <ul>
                <li><a href="index.php">Home</a></li>
                <li><a href="history.php">History</a></li>
                <li><a href="reviews.php">Reviews</a></li>
                <li><a href="#" class="menu-toggle">Menu</a></li>
                <li><a href="location.php">Location</a></li>
            </ul>
        <label for="navbar-checkbox" class="navbar-handle"></label>
        </nav>

    </div>
</div>

CSS:

@media (min-width: 900px) {
    .nav-menu {
        font-size: 1em;
    }
}
.nav-menu {
    padding: 0.5em;
    /*background: #eee;*/
    /*border: 1px solid red;*/
    min-height: 2em;
    line-height: 1em;
}
.nav-menu ul {
    transition: max-height 0.25s linear;
    margin: 0;
    padding: 8px 20px 8px;
    text-align: center;
    text-align: right;
    border: 1px solid red;
}
.nav-menu li {
    transition: visibility .25s linear;
    display: inline-block;
    margin: 0 .75em;
    border: 1px solid blue;
}
.nav-menu li a {
    display: block;
    text-transform: uppercase;
    padding: .70em 1em;
}

.nav-menu li a:hover {
    display: block;
    background: #ffed8b;
    color: #000;
}

@media (max-width: 650px) {
    .nav-menu ul {
        max-height: 0;
        overflow: hidden;
        margin: 0 3.5em 0 1em;
    }
    .nav-menu li {
        visibility: hidden;
        display: block;
        padding: 0.5em 0.6em;
    }
    .nav-menu .navbar-handle {
        display: block;
        float: right;
    }
    #navbar-checkbox:checked + .nav-menu ul {
        max-height: 300px;
    }
    #navbar-checkbox:checked + .nav-menu li {
        visibility: visible;
    }
    #navbar-checkbox:checked + .nav-menu .navbar-handle,
    #navbar-checkbox:checked + .nav-menu .navbar-handle:after,
    #navbar-checkbox:checked + .nav-menu .navbar-handle:before {
        border-color: #aaa;
    }
}
.navbar-checkbox {
    display: none;
}
.navbar-handle {
    display: none;
    cursor: pointer;
    position: relative;
    font-size: 45px;
    padding: .5em 0;
    height: 0;
    width: 1.6em;
    border-top: 0.1em solid;
}
.navbar-handle:before,
.navbar-handle:after {
    position: absolute;
    left: 0;
    right: 0;
    content: ' ';
    border-top: 0.1em solid;
}
.navbar-handle:before {
    top: 0.3em;
}
.navbar-handle:after {
    top: 0.8em;
}
.menu {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}
.menu .navbar-handle {
    position: absolute;
    font-size: 1.2em;
    top: 0.7em;
    right: 12px;
    z-index: 10;
}

CodePen

Answer №1

Don't forget to include the "-toggle" in your CSS selector. Instead of using ".menu", use ".menu-toggle". Here's a snippet to help get you started:

/* Feel free to customize this CSS for your project */
@media (min-width: 900px) {
    .nav-menu {
        font-size: 1em;
    }
}
.nav-menu {
    padding: 0.5em;
    /*background: #eee;*/
    /*border: 1px solid red;*/
    min-height: 2em;
    line-height: 1em;
}
.nav-menu ul {
    transition: max-height 0.25s linear;
    margin: 0;
    padding: 8px 20px 8px;
    text-align: center;
    text-align: right;
    border: 1px solid red;
}
.nav-menu li {
    transition: visibility .25s linear;
    display: inline-block;
    margin: 0 .75em;
    border: 1px solid blue;
}
.nav-menu li a {
    display: block;
    text-transform: uppercase;
    padding: .70em 1em;
}

.nav-menu li a:hover {
    display: block;
    background: #ffed8b;
    color: #000;
}

@media (max-width: 650px) {
    .nav-menu ul {
        max-height: 0;
        overflow: hidden;
        margin: 0 3.5em 0 1em;
    }
    .nav-menu li {
        visibility: hidden;
        display: block;
        padding: 0.5em 0.6em;
    }
    .nav-menu .navbar-handle {
        display: block;
        float: right;
    }
    #navbar-checkbox:checked + .nav-menu ul {
        max-height: 300px;
    }
    #navbar-checkbox:checked + .nav-menu li {
        visibility: visible;
    }
    #navbar-checkbox:checked + .nav-menu .navbar-handle,
    #navbar-checkbox:checked + .nav-menu .navbar-handle:after,
    #navbar-checkbox:checked + .nav-menu .navbar-handle:before {
        border-color: #aaa;
    }
}
.navbar-checkbox {
    display: none;
}
.navbar-handle {
    display: none;
    cursor: pointer;
    position: relative;
    font-size: 45px;
    padding: .5em 0;
    height: 0;
    width: 1.6em;
    border-top: 0.1em solid;
}
.navbar-handle:before,
.navbar-handle:after {
    position: absolute;
    left: 0;
    right: 0;
    content: ' ';
    border-top: 0.1em solid;
}
.navbar-handle:before {
    top: 0.3em;
}
.navbar-handle:after {
    top: 0.8em;
}
.menu-toggle { /* Make sure to correct this part before making adjustments */
    position: absolute;
    top: 0;
    left: 30;


}
.menu .navbar-handle {
    position: absolute;
    font-size: 1.2em;
    top: 0.7em;
    right: 12px;
    z-index: 10;
}
<html>
<body>
<div id="wrapper">
    <div id="header" class="clearfix">
        <span class="logo">Logo</span>

        <input type="checkbox" id="navbar-checkbox" class="navbar-checkbox">
        <nav class="nav-menu">
            <ul>
                <li><a href="index.php">Home</a></li>
                <li><a href="history.php">History</a></li>
                <li><a href="reviews.php">Reviews</a></li>
                <li><a href="#" class="menu-toggle">Menu</a></li>
                <li><a href="location.php">Location</a></li>
            </ul>
        <label for="navbar-checkbox" class="navbar-handle"></label>
        </nav>

    </div>
</div>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Negative margin causes content to conceal itself

I'm facing an issue with using a negative margin for positioning a label. The label is not showing up as expected. Specifically, I need to place a search box on a blue background but when applying a negative margin, the search box does not appear prop ...

The Bootstrap Mobile Navigation transition is not displaying as intended in my CSS coding

On both desktop and mobile screen sizes, I have a white navigation bar. However, for the mobile dropdown menu, I want the background to be grey. I managed to achieve this by targeting .show on smaller screens in the CSS and specifying the grey background ...

The functionality of the Regions plugin in wavesurfer.js appears to be completely nonfunctional

I've been attempting to utilize the Regions plugin from wavesurfer.js, but unfortunately, it's not functioning as expected. Despite trying various methods suggested on different websites, I have yet to achieve success. Below is the snippet of c ...

Automatically adjust the tooltip's position if it extends beyond the width of the browser

I am looking for a way to ensure that when the tooltip width exceeds the browser's viewable area, it will automatically reposition itself so that the content can be fully viewed. It is important that the tooltip does not overlap on the referenced div ...

Tips for avoiding Bootstrap collapse overflow within a container that has overflow-y-scroll

I'm currently facing an issue with a container that has the overflow-y-scroll CSS property. Inside this container, there's a Bootstrap collapse button that expands to show more content when clicked. The problem arises when the expanded content ov ...

Creating visually appealing tables with nested tables using CSS for styling including borders and backgrounds

Looking to create webpages that have a variety of tables, including a main table with a header (marked 2 on the picture) and several data tables for the user (marked 1 on the picture). To style these specific data tables, I've added some custom CSS: . ...

What is the best way to create a layout for Flexbox project boxes with three boxes per row?

My project cards are displaying in a single horizontal line and expanding infinitely to the right, rather than appearing in rows of three as intended. This causes them to extend outside the visible area in a long horizontal strip. See the issue in action ...

When dealing with lengthy product names, Python Selenium may encounter difficulty retrieving the product's name

I need to extract information about all products (such as name, image, price, and link) from . However, I encountered a problem where the product card cannot display the full name of the product if it is too long, resulting in the name and price being retu ...

jqGrid is throwing an error: undefined is not recognized as a function

Currently, I am in the process of trying to display a basic grid on the screen. Following the instructions provided in the jqGrid wiki, I have linked and created scripts for the required files. One essential css file, jquery-ui-1.8.18.custom.css, was missi ...

Issue with grid element not properly scaling using the transform:scale property

I have encountered an issue where a simple grid, with the gaps set to 0, displays a small line when I apply the transform:scale(1.5) css property. I am unsure if this is a bug or if I am doing something incorrectly. Interestingly, the result in Firefox dif ...

Determining the existence of a file on a different domain using JavaScript

One of the key tasks I need to achieve from JavaScript on my HTML page is checking for the existence of specific files: http://www.example.com/media/files/file1.mp3 // exists http://www.example.com/media/files/file2.mp3 // doesn't exist Keep in mi ...

Modify the data displayed on the chart by choosing the desired year from the dropdown options

In my Angular app, I am showcasing a chart that visualizes data based on selected starting and ending years from dropdown menus. The X axis represents 18 cities, while the Y axis displays "IAP" values. To calculate the "IAP" values for each city within the ...

Setting the title of a document in Angular 5 using HTML escaped characters

It seems like a simple problem, but I can't seem to find an easy solution. Currently, I am using the Title service to add titles to my documents and everything is working fine. You can check out the documentation here: https://angular.io/guide/set-doc ...

Is it feasible to execute exe files within a ReactJS environment?

Hey there! I've created a Game Launcher using ReactJS for my Unity game and was wondering if it's feasible to start the game (an exe file) simply by clicking on the play button. Can anyone please advise me on this? ...

How can I integrate custom PHP pages into Odoo Community 12?

I am looking for a way to integrate my custom PHP webpages with the login page of Odoo Community that is already set up and functioning on my server. I want specific users to be redirected to my custom pages after logging in. Any suggestions on how to ac ...

Tips for getting rid of the excess space surrounding an image within a div tag

Placing images inside bootstrap card divs within col divs is my current challenge <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" /> <div class="container"> <div class="row"& ...

Embed a video within an image while ensuring it remains responsive on all devices

I have a picture that resembles something like this one My goal is to embed a video into it while maintaining its aspect ratio when the screen size is reduced. The responsive design should only affect the width since the image will be displayed in portrai ...

Show a picture on top of another picture

Is there a way to overlay an image and text on top of another image, similar to what is done on this website ? ...

To enhance the appearance of an input field, implement the Bootstrap check feature

Using bootstrap in my app, I am dealing with a readonly input where I would like to add a checkmark inside of it. My attempt to simply add <input readonly type="text" id="kyc_status" class="form-control" value="Success ...

Learn how to create a horizontally scrollable ToggleButton using MUI when the ToggleButtonGroup exceeds the screen width

Looking to enhance the responsiveness of my web design project, I aim to create a horizontally scrollable ToggleButton using Mui. The goal is to have the buttons adjust when the screen width becomes too narrow to display all three buttons at once, allowing ...