What could be causing the issue with position: fixed not functioning properly?

Why isn't the position: fixed; property functioning in this CSS code?

body {
    text-align : center ;
    min-width : 770px ;
}
div.wrapper {
    width : 770px ;
    text-align : left ;
    margin-left : auto ;
    margin-right : auto ;
}

div.header {
    color: blue;
    padding: 15px;
    margin: 0px;
    text-align: center;
    position: fixed;
}

div#main {
    margin-left: 30%;
    margin-top: 1px;
    padding: 10px;
}

div.footer {
    color: blue;
    padding: 15px;
    margin: 0px;
    text-align: center;    
}

HTML:

<body>
<div class="wrapper">
    <div class="header">
        <form action="<?php $_PHP_SELF ?>" method="GET">
            Start Date: <input type="text" name="start" pattern="[0-9]{4}"/>
            End Date: <input type="text" name="end" pattern="[0-9]{4}"/>
            <input type="submit" />
        </form>
    </div>
    <hr>


   <div class="main">
       <div id="donutchart" style="width: 900px; height: 500px;"></div>
       <?php
           $i=0;
           foreach ($rows as $row) {
               echo '<div id="chart'.$i.'_div" style="width: 900px; height: 500px;"></div>';
               $i++;
           }
       ?>
   </div>
   <hr>
   <div class="footer">
       ©2014-<?php echo date("Y"); ?> guest
   </div>
</div>
</body>

Answer №1

After some time, I was able to grasp your issue with the code and provide a solution that seems to have resolved it.

Revised CSS:

div.header {
    color: blue;
    padding: 15px;
    margin: 0px;
    text-align: center;
    position: fixed;
    left: 0; top: 0;
    background: #fff;
    width: 100%;
    border-bottom: 1px solid;
}

It appears that adding z-index was essential to bring the header to the front (set as z-index: 10;). Additionally, I included width and a border for aesthetic purposes.

VIEW DEMO HERE

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

Ways to modify the appearance of the Sign up page on Moodle

I'm a newcomer to the world of Moodle, currently using version 2.9. I've created a unique design for my Signup page using HTML5 and CSS. How do I go about integrating this custom page? While I understand how to change the default Login page by m ...

Tips on determining if a string is a properly formatted HTML:

My question is about checking whether selected strings in a web form are valid HTML syntax. How can I achieve this on a button click? function chkhtml() { var code = $("<table><td>"); code.each(function () { if( ...

Low-quality CSS Gradient Design

Hey everyone, Feel free to take a look at my preloader on this link: (Hit ESC as soon as the page loads to pause the website and focus on the loader) Upon closer inspection, you'll notice that there is an issue with the quality of the background l ...

Clear SELECT After Submission

I have a jQuery script and need a function to reset the SELECT input after it has been submitted. <script> $(document).ready(function() { //elements var progressbox = $("#progressbox"); var progressbar = $("#progressbar"); var statustxt = ...

What is the best way to activate an onchange function when using a <select> element?

Is there a way to automatically trigger a JavaScript function without the need for user input, while still having a default option selected? <select class="custom-select" name="" id="timer1numbers" onchange="getSelecte ...

Align the font-awesome icon in the middle of the input box vertically

Is there a way to vertically center the font-awesome icon inside an input box using Bootstrap without setting margins, padding values, or adjusting the height of the input? .inset-0 { top: 0; right: 0; bottom: 0; left: 0; } .inset-y-0 { top: ...

Knockout Table Sorter not refreshing data on update

I'm currently working on a code that updates a table every 5 seconds. I have implemented a table sorter with Knockout.js, however I am facing an issue where the data is being appended to previous data instead of updating it. Below is the code snippe ...

I seem to be having some trouble with my navigation roll-over menu bar, as

Help! I'm having trouble getting my navigation bar to properly overlap the main content on my website. If you could take a look here: that would be greatly appreciated. Please disregard the header position for now, as I am still deciding on its place ...

Is it possible to monitor and keep a record of every modification made to an HTML element?

Can anyone suggest an effective method to monitor changes made to an HTML element? I attempted to utilize JavaScript with jQuery but was unsuccessful. $('div.formSubmitButton input[type="submit"]').change(function(event){ alert( ...

How can I create a layout with cards that are arranged differently on wide screens compared to mobile using bootstrap?

Having trouble with my bootstrap 5.x layout. Can anyone help me achieve a design where the cards display like the left image on desktop/wide screens and like the right image on smaller width mobile screens? I currently have the mobile view showing A-B-C-D- ...

Retrieving Table Cell Values Using Jquery: A Step-by-Step Guide

<table class="table" align="center" id="tblMain"> <tr> <td>Status</td> <td><b><span name="current" value="Dispatch">Dispatch</span></b></td> </tr> </table> JS $(&apos ...

When resizing the window, navigation items vanish

I've implemented the collapse feature using Bootstrap, but encountered an issue where my nav elements disappear when resizing the window. Do you have any suggestions on how to fix this? Here's a snippet of my code: Navb ...

Adjusting the options in the subsequent dropdown menu based on the selection made in the initial dropdown menu

I am currently working on select boxes where values are dynamically added through an array. For example, if I have 4 values in the first select box, I only want to display 3 values in the second select box, excluding the value that has already been selecte ...

Utilize Bootstrap columns to maximize vertical space efficiency

I recently came across a bootstrap layout like this: https://i.sstatic.net/VXBCF.png In this setup, there is a single .row that contains 8 .col-lg-3 divs. However, I noticed that there is excessive vertical whitespace present, which not only looks undesi ...

Tips for maintaining consistent styles in CSS for multiple websites

I am currently working on developing a customizable chatbot widget using react. The goal is to create a chatbot widget that can be easily integrated into any website, similar to the functionality of rasa-webchat. During testing on some websites, I encount ...

The image filter plugin is functioning properly in one project, however, it is not working in

After successfully using a plugin from w3schools to filter elements in one project, I encountered an issue when attempting to implement it in another project. Here is the link to the problematic code pen: https://codepen.io/zakero/pen/mZYBPz If anyone ca ...

Step-by-step guide on accessing and displaying a disc file within a webix application

I am a beginner in webix development and struggling to find documentation or help for my current issue. Within my webix application, I am trying to create a button (let's call it 'View Report') that when clicked will open a file from my loc ...

Animating or transitioning CSS keyframes to an inline value when the page is initially loaded

In my current project, I am working on creating HTML and CSS-based bar representations of percentage values. The structure of the code is as follows: Using HTML: <div class="chart"> <div class="bar" style="width:43%"></div> </div&g ...

What is the best way to ensure items are aligned to the top of the navbar as a picture is enlarged?

I have searched through various similar questions, but none of them have provided a solution to my specific issue. I have attempted multiple suggestions, but none have been successful. (I am working with bootstrap4) Here is the html code I am using: < ...

Guide on leveraging event delegation to trigger a function depending on the id of the clicked element

Although I have experience with event delegation, I am currently facing a challenge in setting up a single event listener that can execute one of three functions based on the ID of the element clicked. Here is the existing code without event delegation: ...