Positioning of header, main content, and footer elements

My webpage is structured into three sections: the header, the main, and the footer. The header at the top has a fixed height of 109px with a 6px border. The main section should extend across the entire page below the header and reach the bottom where the footer is positioned. If there is no content to push it down, the footer should rest at the bottom of the screen. The footer itself is 86px tall due to an 80px height and a 6px border at the top. I need assistance in achieving this layout as I am unsure how to proceed.

html {
  height: 100%;
  box-sizing: border-box;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  padding: 0;
  position: relative;
  margin: 0;
  padding-bottom: 9rem;
  min-height: 100%;
}


/* ---------------------------------------------------------------- */

main {
  margin-top: 109px;
  text-align: center;
  min-height: 100%;
  min-width: 100%;
}

#header {
  background-color: #25211e;
  border-bottom: 6px solid #1d1a18;
  text-align: center;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 103px;
  box-shadow: 0px 0px 14px 2px rgba(0, 0, 0, 0.75);
  z-index: 99;
}

#heading {
  font-family: "Arial";
  color: #c1b497;
  font-size: 45px;
  display: inline-block;
  margin-bottom: 10px;
  margin-top: 15px;
}


/* ---------------------------------------------------------------- */

#footer {
  background-color: #25211e;
  border-top: 6px solid #1d1a18;
  text-align: center;
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 80px;
  z-index: 98;
}

#credit {
  font-family: "Helvetica";
  font-size: 14px;
  color: #c1b497;
  font-weight: 600;
}
<div id="all">
  <header id="header">
    <h1 id="heading">My Page</h1>
  </header>
  <main id="main">



  </main>
  <footer id="footer">
    <p id="credit">FOOTER</p>
  </footer>
</div>

Answer №1

To achieve the desired result, it is recommended to eliminate the padding-bottom attribute from the body, and substitute the margin-top with padding-top & padding-bottom:

html {
  height: 100%;
  box-sizing: border-box;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  padding: 0;
  position: relative;
  min-height: 100%;
}
/* ---------------------------------------------------------------- */
main {
  padding-top: 109px;
  padding-bottom: 86px;
  text-align: center;
}
#header {
  background-color: #25211e;
  border-bottom: 6px solid #1d1a18;
  text-align: center;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 103px;
  box-shadow: 0px 0px 14px 2px rgba(0, 0, 0, 0.75);
  z-index: 99;
} 
<div id="all">
  <header id="header">
    <h1 id="heading">My Page</h1>
    <nav id="navigation">
      <a class="navigationlink activelink" href="index.html">Home</a>
      <a class="navigationlink" href="page1.html">Page1</a>
      <a class="navigationlink" href="page2.html">Page2</a>
      <a class="navigationlink" href="page3.html">Page3</a>
      <a class="navigationlink" href="page4.html">Page4</a>
    </nav>
  </header>
  <main id="main"></main>
  <footer id="footer">
    <p id="credit">FOOTER</p>
  </footer>
</div>

Answer №2

Could you please clarify your question a bit? Nevertheless, I will attempt to provide an answer based on what I understood: Do you require fixed positions and the elimination of unnecessary margins?

html {
  height: 100%;
    box-sizing: border-box;
}
body {
    background-color: #f5f5f5;
    margin: 0;
    padding: 0;
   min-height: 100%;
}

/* ---------------------------------------------------------------- */

main {
    text-align: center;
    min-height: 100%;
  min-width: 100%;
}

#header {
background-color: #25211e;
border-bottom: 6px solid #1d1a18;
text-align: center;
  width: 100%;
  height: 103px;
  box-shadow: 0px 0px 14px 2px rgba(0,0,0,0.75);
  z-index: 99;
}

#heading {
  font-family: "Arial";
color: #c1b497;
font-size: 45px;
display: inline-block;
margin-bottom: 10px;
margin-top: 15px;
}

#navigation {  
margin: 0px;
margin-bottom: 20px;
padding: 0px;

}

.navigationlink {
font-family: "Helvetica";
text-decoration: none;
font-weight: 800;
color: #ffffff;
font-size: 11px;
height: 52px;
letter-spacing: 1px;
margin: 0 10px;
padding-left: 0px;
padding-right: 0px;
position: relative;
text-transform: uppercase;
transition: color 0.3s;
}

.navigationlink:hover {
color: #c1b497;
}

.activelink:hover {
border-bottom-color: #c1b497;
}

.activelink {
border-bottom: 2px solid #ffffff;
transition: color 0.3s;
}
/* ---------------------------------------------------------------- */

#footer {
    background-color: #25211e;
border-top: 6px solid #1d1a18;
text-align: center;
position: fixed;
  right: 0;
 bottom: 0;
  left: 0;
  height: 80px;
  z-index: 98;
}

#credit {
    font-family: "Helvetica";
    font-size: 14px;
color: #c1b497;
font-weight: 600;
}
<div id="all">
<header id="header">
              <h1 id="heading">My Page</h1>
                <nav id="navigation">
<a class="navigationlink activelink" href="index.html">Home</a>
<a class="navigationlink" href="page1.html">Page1</a>
<a class="navigationlink" href="page2.html">Page2</a>
<a class="navigationlink" href="page3.html">Page3</a>
<a class="navigationlink" href="page4.html">Page4</a>
</nav>
            </header>
<main id="main">
      
      
      
</main>
<footer id="footer">
<p id="credit">FOOTER</p>
</footer>
</div>

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

When the Model popup is activated, it is essential for elements to have an adequate color contrast

Our team is utilizing the axe dev tool for accessibility testing. We encountered an issue where elements behind a model popup (Kendo React model with position: absolute) were displaying insufficient color contrast errors. Upon changing the absolute positio ...

What is the best way to access the display property of a DOM element?

<html> <style type="text/css"> a { display: none; } </style> <body> <p id="p"> a paragraph </p> <a href="http://www.google.com" id="a">google</a> &l ...

The initial click event for the input element in Jquery is not functioning correctly

I found a jQuery date selector online and the script looked something like this... <script type="text/javascript> $(document).ready(function () { $("#date3").click(function() { $("#date3").scroller({ preset: 'datetime' }); wheels = []; whe ...

I'm having trouble with jQuery recognizing the left-margin property. Is there a workaround for this issue?

I rarely use jquery, but I wanted to add animation to a side bar. The sidebar menu is 670px with a -670 left-margin. When the user hovers over it, I'd like the left-margin to change to 0px and reveal the hidden content. Upon mouseout, it should return ...

I am looking to extract and gather information from a webpage

Here is the HTML code found in the DOM: <center> "1 file " <br> "has been successfully uploaded." </center> I need to extract the text "has been successfully uploaded." using my method. I attempted using ge ...

What is the best way to assign an identifier to a variable in this scenario?

script.js $('a').click(function(){ var page = $(this).attr('href'); $("#content").load(page); return false; }); main.html <nav> <a href="home.html">Home</a> <a href="about.html">About</a> < ...

How can I address the problem of adjusting the title to match the size of the image in question?

I need help creating a design where an image and h2 title appear on top of the image... Below is a reference screenshot: I am looking to achieve something similar. CSS: h2 { position: relative; letter-spacing: 1px; display: inline-block; positi ...

CSS: The relative positioned element now functions correctly with the inclusion of overflow-x

Is there a way to ensure that the images in the day_time_block cover the title class? I would also like all contents within the day_time_block to be displayed using overflow-x. However, when I add overflow-x: auto; to the scroll div, the images in the d ...

Adjust the border hue of the MUI disabled outline input

I am currently struggling to locate the exact definition of this border color. After inspecting the dom, I cannot seem to find any border style within the input component or its pseudo elements... My main goal is to slightly lighten the color of the input ...

What is the best way to create a div that maintains a consistent size while displaying images inside?

Struggling with a project and attempting to create a fixed div container for uniform picture sizes, I've tested various methods recommended by others but have had zero success in altering the size of my div container. Could it be due to my use of boot ...

Extract image file name and date information (day, month, year) from an HTML form using Angular

The content of the register.component.ts file can be found below: import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-register', templateUrl: './register.component.html', styleUrls: [&apo ...

What is the best way to include a background image in a div within a React component?

I'm currently following a tutorial on creating an RPG game using React. The tutorial can be found at this link. I am trying to replicate the presenter's code by typing it out myself. However, I'm running into an issue when attempting to add ...

Styling just a single div when the state changes

I have a scenario where I am rendering 4 divs based on data fetched from my backend. Each div is colored according to a state change. While I have successfully implemented this, the issue is that all 4 divs can be colored in this way simultaneously. I want ...

Guide to Embedding Dynamic Images in HTML Using VUE

I am venturing into the world of VUE for the first time, and I find myself in need of a header component that can display an image based on a string variable. Despite my best efforts to search for tutorials, I have not been able to find a solution. Header ...

What is the best way to display uploaded images on the server side in a browser using the MEAN stack?

I am currently utilizing the MEAN stack to develop an application that allows users to upload images, preview them, and save them in a MongoDB database via a server implemented with Express. Furthermore, I aim to retrieve these images from the server and d ...

Is there a way to create an X shape by rotating two divs when I click on the container div?

I currently have this setup: code Below is the HTML code: <div id="box"> <div id="line1" class="line"></div> <div id="line2" class="line"></div> <div id="line3" class="line"></div> </div> My go ...

Is there a way to alter a form element based on the selected image?

Below is a code snippet that allows the price in the 'price' div to change based on user selection. <script type="text/javascript"> function showprice(e){ document.getElementById("price").innerHTML = e.getAttribute(&apo ...

What is the best way to create a button with a background image that is also transparent?

Is it possible to set a background image for a button in HTML with a transparent background using CSS? Here is the HTML code I currently have: <button style="background-image: url('../images/example.png');"></button> ...

Effective strategies for integrating Bootstrap and AngularJS without relying on jQuery

Currently exploring AngularJS after experimenting with Twitter's Bootstrap. I appreciate Bootstrap for its simplicity, sleek design, and mobile-friendliness. On the other hand, I have noticed a trend where people recommend using AngularJS over jQuery, ...

The action of JQuery is modifying the value of the checkbox, but it is not visually showing as checked

I am working on a list that contains checkboxes and text, similar to an email inbox. My goal is to be able to check or uncheck the checkbox anytime I click anywhere on the list item (row). To achieve this functionality, I have used the following code withi ...