Checkbox loses its check mark when window is resized

My solution for toggling the sidebar visibility on mobile and tablet devices using CSS3 checkboxes is working perfectly. However, I encountered an issue where resizing the browser window causes the sidebar to become unchecked, resulting in the navigation bar disappearing.

Although I attempted to recreate the error in a JSFiddle, the problem did not occur there. I have provided the code snippet and the link to the website, both of which utilize the same class and id names.

ul, li {
  list-style-type:none;
}

.header__actions__menu {
    display: inline-block;
    font-size: .5625rem;
    font-weight: bold;
}

.header__actions__menu span:before {
    content: "X";
    font-family: 'FontAwesome';
    font-weight: normal;
    position: absolute;
    text-rendering: optimizeLegibility;
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    font-smoothing: antialiased;
    font-style: normal;
    font-size: .875rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.header__actions__menu span {
    background-color: #fff;
    border: 2px solid #000;
    display: block;
    margin: 0 auto 3px;
    position: relative;
    height: 20px;
    width: 22px;
}

.header__actions__close {
    opacity: 0;
    position: absolute;
    transition: opacity .1s linear 1s;
    visibility: hidden;
}

.header__actions__close {
    background-color: #000;
    border-radius: 100%;
    display: inline-block;
    overflow: hidden;
    position: relative;
    height: 22px;
    width: 22px;
    text-indent: -9999px;
}

.header__actions__close:before, .header__actions__close:after {
    opacity: 0;
    transition: opacity .1s linear .2s;
    visibility: hidden;
}

.header__actions__close:before, .header__actions__close:after {
    background-color: #fff;
    content: '';
    left: 50%;
    position: absolute;
    height: 2px;
    width: 14px;
    top: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
}

.header__actions__close:after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/*-- Checked CSS --*/
#mobile-nav:checked ~ .header__actions .header__actions__menu, #mobile-nav:checked ~ .header__actions .header__actions__phone {
    display: none;
}

#mobile-nav:checked ~ .header__actions .header__actions__close {
    display: inline-block;
    opacity: 1;
    position: relative;
    visibility: visible;
}

#mobile-nav:checked ~ .header__actions .header__actions__close:before, #mobile-nav:checked ~ .header__actions .header__actions__close:after {
    opacity: 1;
    position: absolute;
    visibility: visible;
}

/*-- Breakpoints --*/
@media only screen and (max-width: 991px) {
.header__actions li:last-child {
    margin-left: auto;
}
<input type="checkbox" style="display: block;" id="mobile-nav">

<div class="header__actions" data-section="header-account-actions">
  <ul>
    <li>
      <label for="mobile-nav" class="header__actions__menu">
        <span></span>
        Menu
      </label>

      <label for="mobile-nav" class="header__actions__close">Close</label>
    </li>
  </ul>
</div>

Website : (Mobile version only)

Answer №1

I stumbled upon this code snippet on

Located at line 154

$(window).resize(function () {
    self.$menuIcon.prop('checked', false);
    $('body').css('overflow', '');
});

This code snippet changes the checkbox property to false on resize, consider modifying it to true.

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

What is the best way to retrieve data from Firebase and then navigate to a different page?

I am facing an issue with my app where I have a function that retrieves data from Firebase. However, after the completion of this Firebase function, I need to redirect it to another page. The problem is that when I press the button, the redirection happe ...

Is your window.location.hash malfunctioning?

I am facing an issue with changing the background color of a <div id="services> when a specific link (index.html#services) is clicked. I have attempted to use the latest jQuery along with the jQuery Color plugin from jQuery Color. The code snippet I ...

Laravel is failing to send a response when trying to pass a PHP variable using Ajax

When I send an AJAX request to the controller, I am receiving a success alert message. View $(".SendEvents").click(function(e){ e.preventDefault(); var ids = $(this).attr("id"); $.ajax({ type:&a ...

Enhancing Bootstrap Carousel with various effects

My exploration of the web revealed two distinct effects that can be applied to Bootstrap Carousel: Slide and Fade. I'm curious if there are any other unique effects, such as splitting the picture into small 3D boxes that rotate to change the image? ...

PHP will send back a response code of 500, but only if it is submitted

Hey there! I've been working on implementing a two-step authentication system on a website, and I'm encountering an issue with an AJAX post. Every time I try to make the AJAX post, it returns a 500 Error. Oddly enough, when I directly run the co ...

What is the method for accessing specific elements by their ID within a chosen HTML document?

First, I am grabbing an element by its id: var toolbarAreaElement = document.getElementById('toolbarArea'); Now, I want to get another element by Id from the previously selected element (toolbarAreaElement) : var subToolbarElement = tool ...

The functionality of `config.assets.debug = true` fails to

I've encountered an issue with the configuration on development where config.assets.debug = true doesn't seem to work correctly. Instead of having multiple separate JavaScript and CSS file inclusions, I'm getting a consolidated one: <li ...

Unveiling hidden HTML elements with BeautifulSoup: A step-by-step guide

Currently, I am attempting to extract video content from a specific website. Although I can locate the video link using Chrome DevTools, it remains hidden when utilizing BeautifulSoup for extraction. I am hoping for assistance in modifying the code below t ...

Tips for choosing an item within a div -> ul -> li using Selenium

I need help with a menu that displays a list on mouse hover, and I'm trying to click on "Logout". However, the code I've written so far is not giving me the desired result. This is the Java code I have: public void logout() throws Exception { ...

Blazor Shared CSS File

Currently, I have successfully implemented 2 pages in my Blazor app: Login.razor located in the Auth folder AddPerson.razor situated in the Profile directory At this point, I have managed to integrate a CSS file specifically for the AddPerson.razor page ...

Flask Template Failing to Load Local CSS

Hello there, I am currently working on integrating custom CSS into my Flask application. While I had no issues loading Bootstrap, I seem to be facing some difficulties with my local CSS. Below is the method I am using to load my CSS: <link rel="st ...

The mat-table fails to populate with data retrieved from the rest service

I have successfully fetched an array from my REST service and displayed some information from the response on the page. However, I am facing issues populating my mat-table and I'm unsure of the cause. The mat-table was functioning properly in the past ...

What is the process for incorporating ejs into the source attribute of an image element?

Code Snippet: <img class="card-img-top" alt="..."><%= articles.image %><img> Server Setup: const express = require('express') const app = express() const router = require('./routes/article') app ...

Tips for keeping a div visible while hovering over a link using only CSS

Apologies for any language errors in advance. I will do my best to explain my issue accurately: In my CSS, I have created a hidden div that is displayed none by default. When I hover over a link in the navigation bar, I change the display to block, creati ...

Select a date within the Bootstrap datetimepicker input

I implemented the datetimepicker widget from [insert link to the actual website here]. However, I encountered an issue as there was no clear guidance on how to use certain functions such as date, show, hide, etc. This made it challenging for me to set the ...

Decipher complex JSON structures

I am working with a multi-level JSON structure: { "1":{ "name":"PHP", "slug":"/tag/php", "type":"Tag" }, "2":{ "name":"JavaScript", "slug":"/tag/javascript", "type":"Tag" }, "3":{ ...

Make the div stretch to the bottom of the webpage

This question may be a common one, but despite my efforts, I have not been able to find a solution to what seems like a simple issue. Here is the code snippet in question: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

I am unable to display the service response in the Angular component

I'm facing an issue with displaying data in an angular component from a service. The process from the service to the component seems fine, but when I try to use the variable in HTML, it doesn't show the result. For this project, I am using the M ...

Utilizing AJAX in Wordpress to Dynamically Update HREF Links

My website now has AJAX functionality, and you can see a live example at www.mathewhood.com. I am interested in changing the URL format when clicked from To something like , without the /sitefiles/ for security reasons. Below is my code. If anyone is ex ...

What is the best way to integrate a basic jQuery script into WordPress?

After reading through the Codex and various blog posts on implementing jQuery in WordPress, I find it quite frustrating. I managed to successfully load jQuery in the functions.php file, but the available guides are not very helpful as they seem to assume a ...