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

Tips for adding a gradient to your design instead of a plain solid color

I stumbled upon a snippet on CSS Tricks Attempting to replace the green color with a gradient value, but unfortunately, the value is not being applied. I have tried using both the fill property and gradient color, but neither has been successful. Here is ...

Utilizing the value selected in a form to trigger an action method without the use of a query

I am currently utilizing pug to generate pages for my nodeJS server. In this particular case, I am attempting to use the value selected in a form select option to dynamically change the action method. Essentially, the goal is to utilize the group name sel ...

How to remove an event listener that was added within a function in JavaScript?

I am encountering an issue while trying to remove an event listener that was created inside a function. Oddly enough, it works perfectly when I move the event listener outside of the function. See the example below: <body> <div id='myDiv&apo ...

Adding the "input-invalid" class to the input doesn't take effect until I click outside of the input field

When the zipcode field is updated, an ajax call is made. If there are no zipcodes available, I want to mark it as invalid by adding the "input-invalid" class. However, the red border validation only appears when clicking outside of the input field. Is ther ...

I've exhausted all options from stackoverflow with no success. Google Chrome's Autofill feature is wreaking havoc on my theme. Any suggestions on how to tackle this issue?

I designed a template with a stunning CSS layout. All I want is to have a transparent background with white font color, but Google Chrome seems to be causing issues with my theme. What steps should I take? I've exhausted all resources available onlin ...

Tips for successfully passing an image using props in Vuejs without experiencing the issue of disappearing content when there is no image present

Is there a way to make a component that can function with or without an image? Currently, when the component doesn't have an image, other contents and styles disappear. How can I resolve this issue? App.Vue: <template> <div id="app&qu ...

Rapid HTML coding dilemma

Currently, I am in the process of quickly marking up my webpage. One issue I am facing is that I would like my title to be displayed below my <nav> tag instead of beside it. Can anyone provide guidance on how to achieve this? Here is the current HT ...

Steps for modifying material-ui timepicker to display time in a 24-hour format

Presently, I am utilizing a Timepicker from material-ui. It is currently configured with type="time", allowing me to select times throughout the day in 12-hour increments with an AM / PM choice. However, I wish to adjust my picker to a 24-hour format, elim ...

CSS3 Animation displaying text color change on various elements in a continuous loop

I was attempting to create a dynamic animation where multiple texts change color, similar to what you can see on https://vercel.com. I have successfully figured out how to make one text change color using keyframes, but I am struggling to make each text ch ...

Is there a method to incorporate scss into a project without requiring a separate stylesheet?

I am currently working on a Gatsby application that utilizes SCSS. My code snippet looks like this: import React from "react"; import styles from "./mosaic.module.scss"; import Tile from '../tile/tile'; const Mosaic = (): JSX.Element => ( ...

Vuetify Container with a set maximum width that remains fixed

I recently started developing a web application using Vue.js and Vuetify (https://vuetifyjs.com/en/). Currently, I have a basic layout with 3 columns. However, I noticed that the width of these columns is restricted to a maximum of 960px due to some defau ...

Video tag with centered image

For a current project, I am in need of rendering a centered image (a play button) at runtime on top of a video based on the UserAgent. If the userAgent is not Firefox, I want to display the image as Firefox has its own playEvent and button on top of the vi ...

What are some ways to create a div section within a Google Map interface?

Is there a way to create a div area within the Google map iframe? Some of my code is already prepared here (). The image in this link () illustrates exactly what I'm trying to achieve. ...

Utilizing a Chrome packaged app to interact with a local sqlite database through reading and writing operations

Is it feasible to access and manipulate a local sqlite database from within a Chrome packaged app? I am currently able to work with a locally stored JSON file for my app data, but now I also require the functionality to interact with a sqlite database in ...

Tips on automatically adjusting the width of a div to fit the content, maintaining center alignment, and ensuring the contents float to the left

I am facing an issue with a div element that has multiple children. My goal is to have the children neatly fit to the bottom left of the grid when the window expands, utilizing the next available space efficiently. However, as the div expands with the wind ...

Displaying a variable in HTML using PHP before it's actually declared

I have a webpage named search.php My goal is to customize the title/tab tag of the page to display the number of items found along with "Mysearch". Here's what I want it to look like: <head> <title><?php echo $number_count; ?> it ...

What is the best way to dynamically change the color of my component depending on the prop passed to it?

I am facing an issue with the color of my component changing based on the value of the prop 'level'. Despite using states to set the backgroundColor, all components end up having the same color due to the state being altered for every comment. I ...

Steps for choosing the nth HTML row with jQuery

I'm facing a situation where I need to be able to select the nth row of an HTML table based solely on the id of the selected row. You can see exactly what I mean by checking out this JSFiddle Demo <table class="mytable1"> <tr><td i ...

Understanding the significance of 'href = '<? = variable ?>' on an HTML/PHP webpage

I must admit, I have a slight inkling that I'll feel a tad foolish once it's clarified, but could someone kindly explain what the following statement accomplishes? href='<?= $authUrl ?>' This line is extracted from the Google AP ...

Switching carousel background image upon navigation click

I am currently working with a Bootstrap Carousel and I want to customize the background (an image) for each slide. I have 4 slides in total, each corresponding to a specific background image. <!DOCTYPE html> <html lang="en" dir="ltr ...