What is the best way to utilize #checked for displaying or concealing a menu in responsive mode?

Seeking assistance in creating a responsive menu navbar, I experimented with using a checkbox based on recommendations from various websites. However, despite my best efforts, the functionality remains elusive to me (I must admit, my expertise in this area is limited). The button fails to respond when checked or unchecked. If there are more efficient methods of achieving this goal using only HTML and CSS, please share your insights. In an effort to provide context, below is the code snippet. Recognizing that it may be excessive, I apologize for my lack of discretion.

html:

<nav>
        <!--logo-->
        <a href="#" class="logo">TBD</a>
        <!--menu-->
        <ul>
            <li><a href="#" class="active">Landing page</a></li>
            <li><a href="#">about me</a></li>
            <li><a href="#">gallery</a></li>
            <li><a href="#">blog</a></li>
            <li><a href="#">contact</a></li>
        </ul>
        <input type="checkbox" id="check">
  <label for="check" class="checkbtn">
    <i class="fas fa-bars"></i>
  </label>
</nav>

css:

    nav{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
    background-color: #ffffff;
    box-shadow: 2px 2px 12px rgba(0,0,0,0.2);
    padding: 0px 5%;
}

nav ul li{
    float: right;
    display: inline-block;

}

nav ul li a{
    margin: 30px;
    font-family: calibri;
    color: #505050;
    font-size: 19px;
    font-weight: 700;
}

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

#check{
  display: none;
}

...

@media screen and (max-width: 796px) {

    .checkbtn{
    display: block;
    margin-right: 40px;
    color: black;
    }
nav ul {
        margin: 0px;
        padding: 0px;
        background-color: #ebeef4;
        flex-direction: column;
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100vh;
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 1;
        display: none;
    }

    nav ul li {
        padding: 10px;
        display: block;
    }

    nav ul li a{
        font-family: calibri;
        font-size: 1.4em;
        text-transform: uppercase;
        color: #5c5c5c;
    }

    nav ul li a:hover{
        color: #121212;
    }

    #check:checked ~ ul{
        display: block;
        left: 0;
        background: rgba(0,0,0,0.8);

    }

    nav.active ul {
        display: flex !important;
    }

I'm actively trying to grasp this concept better, and I truly apologize for the lengthy post. Thank you for your understanding!

Answer №1

When it comes to check boxes, they are crucial inputs that must be processed by a form. Have you thought about what should occur once the box is checked?

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

Create a fixed navigation for multiple table header rows without using JavaScript, only CSS/bootstrap

My goal is to make multiple rows under the <thead> tag stick while allowing the rest of the table to remain scrollable. I found an answer on SO that demonstrates how to make the header sticky using the position: sticky property, but it doesn't ...

Is there anyone who can identify the issues with this form validation?

This is my first time putting together a contact form and I'm encountering some issues. When I click on the submit button, my website doesn't display the PHP page as intended. Additionally, the validation boxes are not showing up when they should ...

Android TV with Ionic

I am working on an APK for Ionic on Android TV and I am facing an issue with the arrow controls. The APK runs on the device but the behavior is not correct. When using arrows to shift the app, the focus does not work as expected. It skips some divs. Here ...

Generate a two-column table using elements from a foreach loop

I am attempting to showcase the outcomes of a foreach loop in a two-column table format. Here is the code snippet I am using: <table> @foreach (var item in items) { <tr> <td> @item.value ...

What is the best way to move the Grid upward when the above content is not visible?

Let me demonstrate what I have been working on. Currently, I am creating a weather application to explore the functionalities of https://material-ui.com/. I am attempting to prototype an animation inspired by Google Flights, which can be seen here: https: ...

Assist the floats to "ascend" and occupy the available space

The screenshot showcases boxes that have been styled with "float: left". Is there a way to make these boxes float to the first available space in a column? For example, can we move the Music Nation box to the location indicated by the red arrow in the ima ...

Tips for accessing webpage data using pandas

My attempt to extract data from a table on the webpage is proving challenging. The code I am using is as follows: import pandas as pd url="https://datahub.io/sports-data/german-bundesliga" pd.read_html(url)[2] Despite this, the code successfu ...

Using jQuery to show and hide elements on a webpage

One issue I'm facing is changing the content on a page depending on the clicked link. The problem arises when the displayed content for one link persists even after clicking another link, despite setting it to not display when another link is clicked. ...

Displaying several modals with a backdrop on top of one another using Bootstrap

My issue involves two modals: one that displays appointment information with a delete button, and another that serves as a warning before deleting. I want the delete-warning modal to overlay a backdrop on the modal beneath it, graying it out. However, both ...

Ways to conceal one message within another

I am currently working on incorporating Facebook's comments box into my website. My goal is to have the comments that I retrieve through GET requests and display in the template remain invisible to users, but visible to search engines. As part of an ...

Utilizing inter-process communication in Electron to establish a global variable from the renderer process

renderer.js ipcRenderer.sendSync('setGlobal', 'globalVarName').varInner.varInner2 = 'result'; main.js global.globalVarName = { varInner: { varInner2: '' }, iWontChange: ' ...

Enhancing your Vue web application with Bootstrap: A guide to customization

Utilizing bootstrap-4 within my Vue web application has been challenging. I am unable to customize it as explained here. My index.html utilizes Bootstrap CDN, as shown below: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

Is there a way to retrieve just the parent's value?

<div class="island biz-owner-reply clearfix"> <div class="biz-owner-reply-header arrange arrange--6"> <div class="arrange_unit biz-owner-reply-photo"> <div class="photo-box pb-30s"> <a hre ...

Is it possible for me to set my HTML body class as ".body" in CSS?

CSS .body { background: linear-gradient(-45deg, rgb(255, 0, 0), rgba(216, 29, 29, 0.856), #fdfdfdd7, #234cd5, #ffffff); background-size: 400% 400%; background-repeat:no-repeat; animation: gradient 35s ease infinite; height: 100vh; } HT ...

Adding values dynamically to a select dropdown results in an empty field being inserted in the dropdown if the option includes spaces

I am facing an issue with my dropdown select feature, where the value is supposed to be added based on input from a text box. Everything works smoothly when the input in the text box consists of a single word without spaces. However, it fails to add anyth ...

Activate the overflow feature within native-base cards

I have a unique design element on a website that showcases an image overflowing off a card. The image has a negative margin-top of -50, creating this effect. Now I'm trying to replicate this design in react-native using native-base components. Here i ...

If the sidebar is not found on WordPress, delete the CSS code

This situation seems a bit strange when it comes to applying a background color. Here is the main structure: <section class="main-row"> <div class="container"> <div class="row"> <div id="primary" class="col-sm- ...

Looking for assistance in resolving a CSS issue on Google Chrome and Safari browsers

My friend needs some assistance with his website that is currently in development: When viewing the website in Firefox, everything looks fine. However, when using Chrome or Safari, there is a strike-through bug appearing in the product description as show ...

Is it unwise to conceal the horizontal scrollbar?

My webpage includes a jquery slideshow using the jquery circle plugin, featuring the "shuffle" option. var slideshow = $('#slider').cycle({ fx: 'shuffle', shuffle: { top: 0, left: 1300}, .... When the images move out ...

"Encountering an error of undefined index when dealing with multiple file

I've encounter an issue with this code but can't seem to figure out what's wrong. Any help would be greatly appreciated. Kindly refrain from marking it as a duplicate too quickly; I've already gone through similar questions without find ...