Header with absolute positioning doesn't play nice when nudged in Chrome

Take a look at the HTML page on this JSFiddle link: http://jsfiddle.net/rb8rs70w/2/

The page features a "sticky" header created using CSS with the property position: absolute.

...
<body class="body-menu-push">

    <header role="banner">
        <a href="#" class="menu-toggle" id="show-menu">Menu</a>
        <h1 class="logo"><a href="/">Site Title</a></h1>
    </header>

    <nav class="menu" id="main-menu">
        <ul>
            <!-- menu items here -->
        </ul>
    </nav>

    <article class="content">
        <!-- page content here -->
    </article>
</body>
...

Below is the CSS code used:

* {
    margin: 0;
    padding: 0;
}
header[role="banner"] {
    height: 70px;
    font-size: 20px;
    line-height: 70px;
    border-bottom: 2px solid #ccc;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    background-color: #fff;
}
.menu-toggle {
    display: block;
    position: absolute;
    left: 20px;
}
.logo {
    font-size: 20px;
    float: right;
    margin-right: 30px;
}
.menu {
    width: 200px;
    height: 100%;
    position: fixed;
    top: 0;
    left: -200px;
    z-index: 1010;
    background-color: #eee;
}
.menu.menu-open {
    left: 0px;
}
.body-menu-push {
    overflow-x: hidden;
    position: relative;
    left: 0;
}
body.body-menu-open {
    left: 200px;
}
.content {
    width: 400px;
    margin: 120px auto;
}

When clicking the 'Menu' link, a push-menu (#main-menu) slides in from the left (initially hidden), pushing the rest of the page to the right. Clicking the 'Menu' link again hides the push-menu and restores the original page layout.

This functionality works well in Firefox (v31) and IE (v9). However, in Chrome (v36.0.1985.143 m), when the push-menu opens, the 'Menu' link disappears (possibly due to the absolutely positioned header not moving to the right). Interestingly, resizing the Chrome window causes the 'Menu' link to reappear (correctly pushing the header to the right). Despite closing the push-menu afterwards, the sticky header remains displaced to the right.

If you know how to address this issue in Chrome, please share your insights!

Answer №1

Try using the following CSS code:

.main-content.open {
    padding-left: 200px;
}

This should resolve any issues with positioning in Chrome.

You can view a live example here: http://jsfiddle.net/df5s6h8t/9/

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

Using Bootstrap to create a fixed footer on a webpage

Is there a substitute for navbar-static-bottom? I currently have my footer set up like this: <div class="navbar navbar-default navbar-fixed-bottom"> <div class="container"> <p class="navbar-text pull-left">&a ...

What is the best way to have a form open upwards when hovered over or clicked on?

Attempting to create a button in the bottom right corner that will reveal a form when clicked or hovered over. The form should slide open slowly and close after clicking on login, but currently the button is moving down as the form opens. The button also ...

I encountered a difficulty in getting my video to play properly on the Safari browser

I am trying to figure out why my video won't play on Safari, even though it works fine on Google Chrome and Edge. Below is a snippet of my HTML code: <video width="640" height="360" controls="true" autoplay loop muted ...

Tips for avoiding overflow while utilizing animations

In my current project, I am facing an issue with a container div that has the CSS property overflow: auto which cannot be removed. Inside this container, there is another div that toggles between showing and hiding using an animation triggered by a button ...

The serialize() function in jQuery is not functioning as expected

Greetings to all! I attempted to serialize a form using the jQuery method serialize() by its unique ID. Here is the HTML code snippet: <form name="structure_form" id="structure_form" method="post"> <div id="add_sections" class="postbox add_s ...

Enhancing User Experience with CSS

Is there a way to create a link within a div and change the hover color to indicate it's a link? The challenge is that my div contains both an image and text in separate divs. div { :hover { background-color: light cyan; } Currently, when I hov ...

Guide on using jQuery to automatically scroll to the HTML container related to a clicked letter

I am in the process of finalizing my wiki page and I wish to add a specific function. My goal is that when a user clicks on a letter in the alphabet bar, the browser will smoothly scroll to the corresponding letter within the wiki column. However, I am en ...

Jquery's remove function fails to function correctly when used on a cloned element

I am facing an issue where I have a list of rows that need to be deleted. However, when I attempted to use jQuery's remove function, it only removed the original row and not its clone. My goal is for the parent element of the parent to be removed when ...

Locate specific phrases within the text and conceal the corresponding lines

I have a JavaScript function that loops through each line. I want it to search for specific text on each line and hide the entire line if it contains that text. For example: <input id="search" type="button" value="Run" /> <textarea id ...

Tab button that can be easily printed

I'm currently facing a challenge with my HTML code on my website. I have 5 tabs already set up, but I want to add one that redirects users to a printable page that opens the print menu specific to their browser. It seems like there might be an issue i ...

Updates made to the Transform property in Mui Theme are not appearing in the browser

I'm looking to modify the MuiInputLabel.outlined. While I can see various changes when inspecting in the browser, I'm having trouble seeing the transform property change specifically. This is the current configuration of my MuiInputLabel: MuiInp ...

The styling for buttons links is malfunctioning

I am currently developing my own version of Bootstrap and focusing on buttons and links. I have anchor tags within the button element, but the link styling is not displaying correctly. HTML <button class="btn-danger"><a href="#">Danger</a& ...

Problem with Internet Explorer version 9 and above and the Flip Card feature

I have a cool feature for one of my clients where clicking on one div causes another div to flip in its place, like a card flipping over. It's kind of like those portfolio image flippers, but instead of images, it flips divs with content inside. How ...

ChakraUI failing to display on the screen

Exploring Chakra UI in my latest project has been an exciting journey for me. I made sure to install all the necessary dependencies and started importing components from the ChakraUI Docs. Initially, I successfully imported and rendered the button feature ...

What is the method to ensure span elements wrap text without setting a specific width or maximum width on the parent div?

Here is a snippet of code I have generated for displaying warnings or errors in Dojo dialogs: /* Relevant CSS styles */ .l-status-message-wrapper { height: auto; margin-left: 5px; margin-top: 2px; min-height: 15px; } .l-status-message-w ...

Determining the measurements of an svg path without relying on the bounding box

Is there a way to retrieve the dimensions of an svg path and showcase it within a div without relying on the bounding box method? I've noticed that the bounding box can be buggy in Webkit especially with bezier curves. Just so you know, I am currently ...

Please reset the form fields after the most recent edit

I've created a form that includes multiple select elements. When an option is selected, it activates the next select element and updates it with values using Ajax and PHP. However, I'm facing an issue where changing a previous option only resets ...

New programmer seeking to apply a dim effect to the entire photo while also adding a highlight when the image is hovered over

I am looking to add a special effect to my photos where they appear dimmed but highlighted when hovered over. Any guidance on how to achieve this would be greatly appreciated! The image is contained within a flexbox div that also contains a clickable lin ...

Challenge encountered while attempting to implement grid system in ionic framework

I'm completely new to the world of ionic framework, and I really need some assistance in completing this view. Please see the image reference https://i.stack.imgur.com/WOBFw.png I have made an attempt at it with the following code: <div class ...

Utilizing jQuery/Ajax to send an ID parameter to a PHP script

This code is where the user interacts. <html> <head> <title></title> <script src="jquery-1.9.1.js"></script> <script src="jquery.form.js"></script> </head> <body> <?php include 'con ...