The changes to the header's width are not being implemented as expected

I have a header.php file that serves as the header for every webpage on my website. I include it on every page, but on the index page, it covers the entire screen. How can I adjust the height of the header so that it only appears at the top of the webpage? I want the height of the header to be 150px and the width to span the full page.

body {
  font-family: Arial, Helvetica, sans-serif;
  padding: 20px 2px 150px;
  font-size: 13px;
  text-align: right;
  background: #E3CAA1;
}

ul {
  font-size:15px;
  text-align: left;  
  display: inline;
  margin: 0;
  padding: 15px 4px 17px 0;
  list-style: none;
  -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  z-index:100;


}

ul li {
  font: bold 12px/18px sans-serif;
  display: inline-block;
  margin-right: -4px;
  position: relative;
  padding: 15px 15px;
  background: #6ec749;
  cursor: pointer;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  -ms-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;

}

ul li:hover {
  background: #555;
  color: #fff;
}

ul li ul {
  padding: 0;
  position: absolute;
  top: 48px;
  left: 0;
  width: 140px;
  -webkit-box-shadow: none;
  -moz-box-shadow: none;
  box-shadow: none;
  display: none;
  opacity: 0;
  visibility: hidden;
  -webkit-transiton: opacity 0.2s;
  -moz-transition: opacity 0.2s;
  -ms-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  -transition: opacity 0.2s;
}

ul>li:last-child ul {
  right: 4px;
  left: auto;
}

ul li ul li {

  background: #555;
  display: block;
  color: #fff;
  text-shadow: 0 -1px 0 #000;
}

ul li ul li:hover {
  background: #666;
}

ul li:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
}
li{
font-size:20px; 

}
a {
  outline: none;
  text-decoration: none;
  padding: 2px 1px 0;
  color:white;

a:link {
  color: red;
}

a:visited {
  color: purple;
}

a:focus, a:hover {
  border-bottom: 1px solid;
  color: purple;
}
The main page where this header is included:

</head>
    <body>

        <?php include('includes/header.php');?>    
      <!-- <?php include('includes/sidebar.php');?>-->
            <main class="mn-inner">
                <div class="row" style="display: block;  margin-left: auto;  margin-right: auto;">
                    <div class="col s12">
                        <h4 style="text-align:center;">Change Password</h4>
                    </div>
                    <div class="col s6 m6 " style="position:fixed;margin: auto;  background-color: #f3f3f3;top: 40%; left: 25%;" >
                        <div class="card" >
                            <div class="card-content">

                                <div class="row">
                                    <form class="col s12" name="chngpwd" method="post">
                                          <?php if($error){?><div class="errorWrap"><strong>ERROR</strong>:<?php echo htmlentities($error); ?> </div><?php } 
                else if($msg){?><div class="succWrap"><strong>SUCCESS</strong>:<?php echo htmlentities($msg); ?> </div><?php }?>
                                        <div class="row">
                                            <div class="input-field col s12">
<input id="password" type="password"  class="validate" autocomplete="off" name="password"  required>
                                                <label for="password">Current Password</label>
                                            </div>

  <div class="input-field col s12">
 <input id="password" type="password" name="newpassword" class="validate" autocomplete="off" required>
                                                <label for="password">New Password</label>
                                            </div>

<div class="input-field col s12">
<input id="password" type="password" name="confirmpassword" class="validate" autocomplete="off" required>
 <label for="password">Confirm Password</label>
</div>


<div class="input-field col s12">
<button type="submit" name="change" class="waves-effect waves-light btn indigo m-b-xs" onclick="return valid();">Change</button>

</div>



                                        </div>
                                       
                                    </form>
                                </div>
                            </div>
                        </div>




                   
                    
                
                </div>
            </main>

        </div>
        <div class="row">
        <?php include('includes/footer.php');?>
        <div>
        <!-- Javascripts -->
        <script src="assets/plugins/jquery/jquery-2.2.0.min.js"></script>
        <script src="assets/plugins/materialize/js/materialize.min.js"></script>
        <script src="assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
        <script src="assets/plugins/jquery-blockui/jquery.blockui.js"></script>
        <script src="assets/js/alpha.min.js"></script>
        <script src="assets/js/pages/form_elements.js"></script>
        
    </body>
</html>
<?php } ?> 

Answer №1

Please review the code below where I have included some HTML to structure it using header and nav.

This response is based on my interpretation, but having an image of your expectations would be beneficial.

When structuring in HTML, ensure that the header is placed within a header container. Typically, this header utilizes display:flex to enhance flexibility in the layout.

body {
  font-family: Arial, Helvetica, sans-serif;
  padding: 20px 2px 150px;
  font-size: 13px;
  text-align: right;
  background: #E3CAA1;
  margin: 0; /********* ADDED TO clear auto margin add by snippet *****/
}

header{ /**************** ADDED ***********/
  display:flex;
  height: 150px;
  margin-left: -2px;
  margin-right: -2px;
  padding-right: 8%; /*** Make sure that the nav is correctly position in centered ***/
}

nav{ /**************** ADDED ***********/
  text-align: center;
  margin: auto;
}

ul {
  font-size:15px;
  text-align: left;
  display: inline;
  margin: 0;
  padding: 15px 4px 17px 0;
  list-style: none;
  -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
  z-index:100;


}

ul li {
  font: bold 12px/18px sans-serif;
  display: inline-block;
  margin-right: -4px;
  position: relative;
  padding: 15px 15px;
  background: #6ec749;
  cursor: pointer;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  -ms-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;

}

ul li:hover {
  background: #555;
  color: #fff;
}

ul li ul {
  padding: 0;
  position: absolute;
  top: 48px;
  left: 0;
  width: 140px;
  -webkit-box-shadow: none;
  -moz-box-shadow: none;
  box-shadow: none;
  display: none;
  opacity: 0;
  visibility: hidden;
  -webkit-transiton: opacity 0.2s;
  -moz-transition: opacity 0.2s;
  -ms-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  -transition: opacity 0.2s;
}

ul>li:last-child ul {
  right: 4px;
  left: auto;
}

ul li ul li {

  background: #555;
  display: block;
  color: #fff;
  text-shadow: 0 -1px 0 #000;
}

ul li ul li:hover {
  background: #666;
}

ul li:hover ul {
  display: block;
  opacity: 1;
  visibility: visible;
}
li{
font-size:20px; 

}
a {
  outline: none;
  text-decoration: none;
  padding: 2px 1px 0;
  color:white;
}

a:link {
  color: red;
}

a:visited {
  color: purple;
}

a:focus, a:hover {
  border-bottom: 1px solid;
  color: purple;
}

.nav-logo{ /**************** ADDED ***********/
  width:8%;
  align-self: center;
}
<header> <!-- ADDED -->
  <a class="nav-logo" href="dashboard.php"> <!-- ADDED class nav-logo -->
    <img src="https://images.freeimages.com/images/large-previews/07a/beach-soft-light-1379401.jpg" width=100% align=left style="display:block;"><!-- MODIFIED width:8% to 100% -->
  </a>
  <nav> <!-- ADDED -->
    <h4 style="color:blue;text-shadow: 4px 4px 8px #c2d4ff; padding-right:10px;font-weight: bold;">STATIONERY MANAGEMENT SYSTEM </h4>
    
    <ul >
      <li ><a href="myprofile.php"style="color:black;" >My Profile</li>
     
       <li>
             Stationery Details 
             <ul>
          <li><a href="apply-stationery.php">Apply Stationery</a></li>
         <li><a href="stationeryhistory.php">Stationery History</a></li>
                               
        </ul>
      </li>
       
      <li ><a href="emp-changepassword.php" style="color:black;"  >Change Password</a></li>
      <li ><a href="logout.php" style="color:black;"  >Log-Out</a></li>
     
    </ul>
  </nav> <!-- ADDED -->
</header> <!-- ADDED -->

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 locking the table header and left column in place without any border flickering

I have been tackling the task of organizing table data recently. I managed to fix the table header and left column using jQuery, which is working fine. However, I noticed that when I scroll through the table, the borders start flickering. When I set the ba ...

Trigger the dimming effect on the webpage when HTML5 video starts playing

After using this particular script: <script> myVid=document.getElementById("video1"); myVid.oncanplay=alert("Can start playing video"); </script> http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_av_event_canplay A notification windo ...

Update the jQuery script tag with new content - rewrite everything

I am facing an issue with jquery. I need to change the link to src only when "document.write" is present. Below is my code: myscript.js document.write("TEST ABCD"); test.html <html> <body> <button id="example">click me</button&g ...

Enrich your HTML using AngularJS

CSS <div class="container"> <section> <p>{{content}}</p> </section> </div> script.js (function () { var script = function ($scope){ $scope.content = "example"; } }()); I am currently ...

Issue with printing data consecutively using Javascript

My JavaScript code aims to display the content of the body tag again when the add button is clicked. The purpose is to add authors, with each author being added in sequence. For example, if there is only 1 author present, the user simply selects whether th ...

Refreshing the images array in the DOM using ajax technology

I have a webpage with various images scattered under a table, like in the example of homepage.htm: <table id="imagesTable"> <tr> <td> <img src="img1.png"> <div> <img src= ...

My Bootstrap and media query seem to be failing to make my webpage responsive. What

When I convert my website to mobile mode, it zooms the entire page and leaves white space from top to bottom on the right side. How can I fix this issue? Here is the link to my website: Image depicting the white space in mobile mode: https://i.sstatic.n ...

What could be causing the malfunction in this multi-select code developed by loudev?

I tried adding this link: After following the instructions, the code is still not functioning correctly. I made sure to include jQuery scripts as well because I thought they might be necessary. I'm having trouble identifying where the mistake lies. ...

What is the process for determining the remaining number of divs after deletion?

Within my HTML document, I have a total of eight div elements. Through the use of jQuery, I managed to extract the number of these divs and display it within the .num div. However, when I proceed to delete one of the div elements by clicking the designate ...

The HTML Style for implementing HighChart title text does not work when exporting files

I have inserted the <br/> and &nbsp; HTML tags into the HighChart titles. The style changes successfully appear in the chart view, but unfortunately, when exported as PNG or JPEG images, the text style fails to apply in the resulting images. To s ...

"Automatically scroll back to the top of the page once new content

Is there a way to automatically scroll the page to the top after content has been loaded via Ajax? Here is the code I am using to display the content: $(document).ready(function () { var my_layout = $('#container').layout(); $("a.item_l ...

An error occurred while trying to retrieve a resource from the bower_components directory using Vue.js CLI

I encountered an error in my project when trying to reference CSS and JS files. Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/bower_components/bootstrap/dist/css/bootstrap.min.css This is how my file ...

The JavaScript function does not function properly when it is called from another function

I tried my hand at creating a simple website for personal use, where I could input and edit text in an organized manner. A key feature I wanted was the ability to add new text fields dynamically by clicking a button, but it turned out to be more challengin ...

Modify the background color of an R chunk in a bookdown gitbook

Is there a method to eliminate the grey background color in order to display the colorful class? https://i.sstatic.net/l1Hhi.png https://i.sstatic.net/4aHMF.png ...

Adjusting Size of Picture and Text on Card

I am currently testing out different effects using the materializecss framework. My goal is to adjust the size of the image and content on a card when the user hovers over it, but I'm having trouble figuring it out. .card:hover .card-image { he ...

Substitute the images with links provided in an external text file

I have a function that I use to replace avatars of players with custom images. Currently, I have three replacement links hardcoded into a Chrome extension. However, I want the function to read an external txt file to dynamically build an array so that I ca ...

Having trouble getting past the initial iteration in Angular's modal system?

Having trouble generating a modal for every iteration in ngFor. The data passed to the modal seems to be stuck in the first iteration and doesn't change with each iteration. Any ideas on how to solve this? <div class="container"> & ...

Enabling multiple selections in a dropdown menu increases the flexibility for users to choose multiple options

I want to learn how to use HTML5 to create a dropdown menu that pulls data from a database but displays like the image provided. I am looking for the functionality to select multiple locations, a button to select all or remove all, and display the selectio ...

The text on my website is experiencing a cropping issue on the right side

I'm having an issue where the right side of all the text on my website is being cut off. I've tried using Firebug to inspect the element, but it's always a paragraph text and they have different parent divs. I'm not sure what CSS adjust ...

Eliminate the margin on the subnavigation menu

Hey there, I'm looking to adjust the layout of my menu buttons by removing the left and right "margins" (if that's the correct term), so they all fit neatly inside the navigation bar. https://i.sstatic.net/udes8.png I want to ensure that all th ...