HTML: Incorporating a Header and Footer with Dynamic Content that meets specific requirements

I'm currently facing a challenge in creating a webpage that requires a normal header, sticky footer, and fluid body content stretched vertically without using absolute positions due to a page min-height requirement of 780px.

While I managed to achieve this using tables, I am keen on avoiding them and also want to steer clear of JavaScript or jQuery. The sticky footer should remain fixed until the minimum height is reached.

I have tried implementing the typical sticky footer layout with the pusher element but encountered issues when setting the main content's height to 100% (likely due to a bug with the wrapper's height: auto property).

Here's an example image illustrating the desired outcome:

Feel free to refer to my current progress on JS Fiddle: http://jsfiddle.net/6qatg/

The provided code snippet:

<body>
    <table class="wrapper">
        <tr><td id="topBar" class="topBar">

        </td></tr>

        <tr><td valign="top" id="mainContent" class="mainContent">  
        </td></tr>

        <tr><td class="footer" id="footer">
        </td></tr>

    </table>
</body>

html{
    min-width: 790px;
    min-height: 300px;
    font-family: 'Open Sans', sans-serif;
    height: 100%;
}

body{
    font-family: 'Open Sans', sans-serif;
    /*border: 2px solid black;*/
    height: 100%;
    min-height: 300px;
    min-width: 790px;
}
*{
    margin: 0;
}

.wrapper {
    height: 100%;
    width: 100%;
}
.footer {
    height: 35px;
    background-color: #00F8FD;
    width: 100%;
}

.topBar{
    height: 75px;
    width: 100%;
    background-color: #00F8FD;
}

.mainContent{
    background-color: #EEF8FD;
    height: 100%;
}

Your help and insights are greatly appreciated.

Answer №1

Have you considered placing the header and footer inside the content container? I set the minimum height to 500 for demonstration purposes in the fiddle, ensuring that there are no scroll bars and the footer remains at the bottom when the height is set to either 500 or 760.

Check out this example on http://jsfiddle.net/carbontype/FYe2b/

HTML

<div class="contain">
    <div class="content">
        <div class="header">Header</div>
        <div class="data">Hello, World!</div>
        <div class="footer">Footer</div>
    </div>
</div>

CSS

*{box-sizing:border-box;}
html, body{height:100%; margin:0px; padding:0px;}
.contain{width:100%; height:100%;}
.header{height:50px; position:absolute; top:0px; width:100%; background:red; z-index:10;}
.content{height:100%; position:relative; background:green; min-height:500px;}
.content .data{padding:10px;}
.content .footer{position:absolute; bottom:0px; left:0px; width:100%; background:pink;}

Answer №2

It seems like I have grasped the concept of what you're looking for. If not, my apologies.

<div class="wrapper">
<div class="heading">header</div>
<div class="content">
    <div class="data">hello 123</div>
    <div class="footer">footer</div>
</div>

*{box-sizing:border-box;}
html, body{height:100%; margin:0px; padding:0px;}
.wrapper{width:100%; height:100%;}
.heading{height:50px; position:fixed; width:100%; background:red; z-index:10;}
.content{height:100%; position:relative; background:green; min-height:790px;}
.content .data{padding:80px 10px 10px 10px;}
.content .footer{position:absolute; bottom:0px; left:0px; width:100%; background:pink;}

Answer №3

To achieve this effect, you can use the CSS property position:fixed for both the header and footer elements (.topBar,.footer). Additionally, give the main content area (.maincontent) a min-height:780px; along with some padding to adjust for the fixed header and footer.
Example: http://jsfiddle.net/EN3Pj/1/
HTML:

<div id="topBar" class="topBar"></div>
<div id="mainContent" class="mainContent">
   Your content goes here...
</div>
<div class="footer" id="footer"></div>

CSS

html{
    min-width: 790px;
    font-family: 'Open Sans', sans-serif
}

body{
    font-family: 'Open Sans', sans-serif;
    /*border: 2px solid black;*/
}
*{
    margin: 0;
}

.wrapper {
    height: 100%;
    width: 100%;
}
.footer {
    height: 35px;
    background-color: #00F8FD;
    width: 100%;
    bottom:0px;
    left:0px;
}
.topBar, .footer{
    position:fixed; //ensure header and footer remain fixed
}
.topBar{
    height: 75px;
    width: 100%;
    top:0px;
    left:0px;
    background-color: #00F8FD;
}

.mainContent{
    background-color: #EEF8FD;
    min-height:780px; //set minimum content height
    padding-top:75px; //adjust for header height
    padding-bottom:35px;
}

Answer №4

Does this fit the bill? It's a basic overview, but I believe it covers what you need.

http://jsfiddle.net/D8yk7/

HTML:

<body>
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
</body>

CSS:

#header {
    width: 100%;
    position: fixed;
    height: 75px;
    background-color: #00F8FD;
}

#content {
    height:600px;
    background-color: red;
    width: 100%;
}

#footer {
    height: 35px;
    width: 100%;
    background-color: #00F8FD;
}

Answer №5

If the auto height property does not work for the wrapper, keep it at 100%.

http://jsfiddle.net/6qatg/2/

        <div class="wrapper">
        <div    id="topBar" class="topBar">

        </div>

    <div id="mainContent" class="mainContent">  
        </div>

        <div class="footer" id="footer">
        </div>

CSS

  html{
min-width: 790px;
min-height: 300px;
font-family: 'Open Sans', sans-serif;
height: 100%;
  }

 body{
font-family: 'Open Sans', sans-serif;
/*border: 2px solid black;*/
height: 100%;
min-height: 300px;
min-width: 790px;
}
 *{
margin: 0;
}

 .wrapper {
height: 100%;
width: 100%;
}
   .footer {
height: 35px;
   background-color: #00F8FD;
width: 100%;
  }

.topBar{
height: 75px;
width: 100%;
background-color: #00F8FD;
}

 .mainContent{
background-color: red;
height: 100%;

}

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

PHP Solution: I'm working on a page that is accessed using the post method. However, I need to defer the execution of certain code until after the page has finished

Apologies for the confusing title, but I'm struggling to succinctly explain my issue: I have a web page that is accessed through a button. When this button is clicked, specific data (a unique identification name) is sent to the page I want to view. Ho ...

Maintaining visibility of entries in collapsed Bootstrap 4 navbar/menu

This is a question that pertains to Bootstrap 4, similar to one found on Stack Overflow, but specific to this version. I am struggling to include right-justified entries in the BS4 navbar that remain visible even when collapsed. I have spent an entire aft ...

Creating an attention-grabbing alert bar positioned above the menu

When I attempted to add this alert bar to my website, I encountered an issue where it was being hidden behind my menu. Some sources suggest that using z-index and position:absolute can resolve this problem by positioning one element above the other, but th ...

Adjust the height of column divs to equal the height of their parent container

Looking for a solution: I have multiple divs in a column layout and I want them to expand to match the original height of the parent. The parent's height is not fixed as it is part of a flex-based page design. Can this be done? In the example provid ...

Identifying input fields using XPath depending on their associated labels

I'm trying to figure out why an XPath query I found returns multiple results when selecting an input based on its label. The first XPath query I used, //input[@id=(//label[.='Max Driving Time_h']/@for)], retrieves 3 inputs even though only o ...

What steps can I take to stop the datepicker from altering the value of the previous row?

I have implemented a datepicker function using React Bootstrap for each table row. The issue I am facing is that when I change the date in the first row, it correctly updates. However, when I try to change the date in the second, third, and subsequent rows ...

Displaying the Ionic loading spinner on the entire page rather than a restricted small box

Right now, I'm able to implement a basic loading effect, but it appears as a small box. presentCustomLoading() { let loading = this.loadingCtrl.create({ content: 'Loading Please Wait...' }); loading.present(); } However, I ...

Achieving a bold border on top of an image without altering the image's dimensions

I'm in need of Photoshop-like selection functionality, but when I add a border to the enclosing div that holds the image, the image ends up smaller by twice the thickness of the border. How can I fix this issue? I have attempted a solution by adding ...

Instructions for implementing onclick functionality on an iframe element

Is it possible to use the onclick event in an iframe tag to call a JavaScript function? I have integrated a Facebook like button on my website using an iframe code. When a user clicks on the like button, I would like them to be redirected to a 'thank ...

The jsPdf library performs well on medium-sized screens like laptops, but when downloaded from larger monitor screens, the PDF files do not appear properly aligned

In the code snippet below, I am using html2canvas to convert HTML to PDF. The PDF download works fine on medium screens, but when viewed on larger screens, some pages appear blank and the content order gets shuffled. How can I resolve this issue so that th ...

Ways to personalize your profile picture input similar to Facebook

Trying to customize my profile picture like the Facebook update design, but encountering issues. I have an external bootstrap CSS file and want it to look like this image: https://i.sstatic.net/QbmIh.png HTML <div class="user-thumb user-thumb--edit ...

Menu bar does not extend fully across the screen

I'm struggling to get my navigation bar to cover the entire right side as seen in the picture. I've tried everything and still can't seem to figure it out. Any suggestions would be greatly appreciated. <!doctype html> <html lang="e ...

Alignment of Inline SVG in HTML

I am struggling to align an inline SVG within a bounding DIV correctly, as shown in this example. <!DOCTYPE html> <html> <body> <div style="border: 1px solid black; height: 50px; width: 100px; vertical-align:top;"> < ...

A guide to mastering the art of descending using three distinct class types

My script is functioning properly for a single class, but it fails to work for multiple classes with the same purpose. I attempted to transfer from div (#panel) to class (.panel) as I am using several classes. However, this adjustment did not resolve the i ...

What could be the reason that my d3.tooltip is not functioning properly for these specific two lines on the chart?

I am currently experiencing issues with the d3.tool tip for my line charts. Additionally, I would like to adjust the y-axis scale to create larger gaps between the lines. Below are the codes used to generate the line charts: <!DOCTYPE html> <meta ...

Personalizing the form controls in Bootstrap for selection options

Utilizing Bootstrap's form-control class helps maintain a consistent style for both form input and select option elements. However, when using form-control on select elements, it results in an unsightly drop-down button appearance in Firefox.https://i ...

Transform a button to function like a checkbox in Knockout JS

Essentially, I have implemented a feature on my website where a button changes its color from green to grey and vice versa when clicked, giving the illusion of turning on and off. Below is the JavaScript and HTML code for this button: <script> $(&ap ...

dynamic resizing, uniform dimensions

Is it possible to use CSS to ensure that an image is 100% the width of a fluid div without distorting the square shape? The goal is to match the height to the width for a cohesive look. Currently, I am using the following code for fluid width: .img{ max ...

How to distinguish between clicking once and double clicking in jQuery

Currently, I am developing a basic tic tac toe game for two players with the help of jQuery. The main requirement is to insert an "X" when the user single clicks and an "O" when they double click on the designated square. Here is how I achieved this functi ...

Excessive content within div

Need help with fixing the height of a div using asp.net. Currently, I am hiding overflow content and looking for a solution. Here's my code snippet: <div id="Content" style="height: 90px !important; overflow: hidden; text-decoration: none; text-ov ...