Sleek CSS3 Slide Menu - Smooth Transition to Top when Sliding

I have been experimenting with a CSS-only slide menu.

Essentially, I set the nav menu position to fixed with top: 0 and right:-200 using radio buttons for control.

<input type="radio" id="nav-expand" name="nav" />
<input type="radio" id="nav-collapse" name="nav" checked="checked" />
<header>
    <div class="logo">
        <h1>Header Text</h1>
    </div>
    <label for="nav-expand" class="btn-nav-expand">
        <span class="top"></span>
        <span class="middle"></span>
        <span class="bottom"></span>
    </label>
    <label for="nav-collapse" class="btn-nav-collapse">
        <span class="top"></span>
        <span class="middle"></span>
        <span class="bottom"></span>
    </label>
    <nav>
        <ul>
            <li><a data-title="Home">Home</a></li>
            <li><a data-title="News">News</a></li>
            <li><a data-title="Our People">Our People</a></li>
            <li><a data-title="About Us">About Us</a></li>
            <li><a data-title="Product and Services">Product and Services</a></li>
            <li><a data-title="Case Studies">Case Studies</a></li>
            <li><a data-title="Contact Us">Contact Us</a></li>
        </ul>
    </nav>
    <label for="nav-collapse" class="overlay"></label>
</header>

When clicked, it uses translatex(-200px) to move the body content and reveal the menu.

The main issue is that when scrolled down, the content always jumps back to the top. My goal is for the content to remain in place so users can cancel the menu and continue reading without interruption.

You can see the problem demonstrated in this Pen - scroll the main content and then open the menu: CodePen. The content consistently resets to the top.

Another problem occurs when the menu is visible - if you scroll on the menu part, it scrolls the main content instead of the menu itself.

Answer №1

I managed to find a solution to my problem on my own.

The issue was caused by the positioning of the two radio buttons. By adding visibility: hidden; to each radio button, I was able to fix the problem.

    <input type="radio" id="nav-expand" name="nav" />
    <input type="radio" id="nav-collapse" name="nav" checked="checked" />

    #nav-expand,
    #nav-collapse {
        visibility: hidden;
    }

Check out the updated CSS in this Code Pen.

Although this resolved one issue, there is still another problem remaining. When the menu is visible and you scroll over it, it scrolls the main content instead of the menu itself.

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 steps should I follow to create a photo gallery similar to Facebook?

I am currently developing a 4x3 image gallery showcasing pictures sourced from a database. Each picture varies in size. Utilizing Bootstrap and CodeIgniter, I create rows and columns for each image. My goal is to ensure that wide images adjust to the heigh ...

Inline-block divs styled with CSS3 are causing a white gap to appear at the top of

I have been searching for solutions to my problem, but I can't seem to find one that works. My goal is to create two columns that each take up 50% of the screen width. However, I am facing an issue where there is a gap at the top that I cannot seem t ...

What is the significance of an empty href attribute in the HTML <base> tag?

If my website URL is: http://example.com/path/to/dir/index.html And I decide to proxy this page through: http://proxyserver.com/path/to/dir/index.html. I would like all relative URLs on the page to be resolved by proxyserver.com instead of example.com. Wh ...

The content of the served HTML Table remains static and requires a server restart for any updates to

Having been encountering this issue for quite some time, I have searched extensively for a solution but to no avail. Therefore, I am taking matters into my own hands and posing the question myself. The dilemma is as follows: https://i.stack.imgur.com/UZrQ ...

Displaying the product quantity counter in the shopping cart immediately after adding the item

My website has a shopping cart quantity counter that doesn't update immediately when a product is added. Instead, it requires a page reload or navigation to another page for the change to be reflected. I would like the quantity counter to show the pro ...

What is the best way to implement a function on every item within a specific class?

I'm new to coding and I have a website that showcases job listings. I want to create a function that dynamically changes the logo of a company based on the first 50 characters of the company name mentioned. The current function only works for the firs ...

A comprehensive guide on adjusting the height of images dynamically using only CSS

Calling all CSS experts: I'm curious if it's doable to replicate the image scaling effect seen on this website using only CSS? Please note that the images only begin scaling when the height of the browser window changes, not its width. (I menti ...

changing the elements' classes by using a carousel

Having trouble with a custom carousel and unable to use the standard Bootstrap carousel. This is how my code is structured: Images: <img src="1.img"/> <img src="2.img"/> <img src="3.img"/> Prev / Next buttons: <div class="left ...

The functionality of List.js is currently not optimized for use with tables

I'm currently experimenting with list.js in order to create a real-time search feature for a table. I have successfully tested it on lists (similar to the example provided at ). However, I am facing difficulty replicating this functionality for tables ...

I am experiencing issues with my HTML select list not functioning properly when utilizing a POST service

When using Angularjs to automatically populate a list with *ngFor and then implementing a POST service, the list stops functioning properly and only displays the default option. <select id="descripSel" (change)="selectDescrip()" > <option >S ...

Vue is currently operating in development mode

I keep receiving this notification each time I visit the site: Vue is currently running in development mode. Remember to switch to production mode when deploying for production. Find more helpful tips at .... I came across a solution from someone suggest ...

The process of altering a span label's class with JavaScript

I am currently working with an HTML element that looks like this: <dd><span class="label label-success" id="status">Production</span></dd> My goal is to update it to: <dd><span class="label label-warning" id="status"> ...

What causes the difference in behavior between absolute positioning in <button> and <div>?

I am noticing that the code below is not positioning my span to the top-left corner of the button as I expected. Can anyone explain why? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> &l ...

Issue with different domains causes GET requests to be changed to OPTIONS requests

In my recent request and response interaction, I encountered an issue with the Access Allow Control Origin being set to *. Remote Address:xx.xxx.xxx.xxx:xx Request URL:http://api-test.example.com/api/v1/sample Request Method:OPTIONS Status Code:405 Method ...

What's going on with the background color? It doesn't seem

I have incorporated Bootstrap into my html code and I am attempting to modify the background color of a div when the screen resolution changes from large to medium or small. Even though I have added a class, the change does not reflect when adjusting the ...

I have a slight confusion when it comes to using HTML frames

Currently, I am in the process of creating a static webpage for an online bookshop. The layout is divided into three frames: top left, and right, each serving a specific purpose. The top frame contains the title, the left frame displays all available boo ...

Discovering components with identical html attributes in Selenium

I am currently developing a web crawler using Python 3.8. My goal is to convert the table below into a pandas dataframe using Selenium, Pandas, and BeautifulSoup. <table class="no_border_top" width="95%" align="center"> ...

Locate the coordinates on an HTML5 canvas that correspond to a specified color

Is there a more efficient method to identify the coordinates of pixels with a particular color without looping through every pixel in the image? ...

The device-width value in the viewport width setting is causing issues

My angular app desperately needs a mobile responsive design as it currently looks dreadful on mobile devices. I've tried adding <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=yes">, but ...

Superceding Meta Character Encoding Statements

Have you ever wondered what happens when two older-style character encoding declarations are used in a webpage? Will the first declaration override the second, or vice versa? Or will they both be ignored and excluded from the encoding algorithm? For Ex ...