To create a complete layout without relying on fixed positioning, ensure that the header, container, and footer collectively

Is there a method to ensure the header, container, and footer encompass the entire layout without using fixed positioning in CSS? Check out this HTML fiddle for reference.

<div class="wrapper">
  <header>
    <img src="https://www.ecobin.com.au/skin/frontend/ultimo/default/images/footer_grass.jpg" alt="">  
   </header>
  <div class="container">
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type 
and scrambled it to make a type specimen book.
    </p>
  </div>
  <footer>footer content goes here</footer>
</div>

CSS:

header img {
  width: 100%;
}

footer {
  height: 40px;
  background: #666;
  color:#fff;
}

Answer №1

Is this what you had in mind?:

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
#page {
  height: 100%;
}
#header {
  height: 50px;
  background: yellow;
}
#content {
  height: calc(100% - 100px);
  background: grey;
  overflow: auto;
}
#footer {
  height: 50px;
  background: blue;
}
<div id="page">
  <div id="header">Header</div>
  <div id="content">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>
  <div id="footer">Footer</div>
</div>

Answer №2

The current layout of your page is set up in a way that keeps the header, content area, and footer in place without shifting unless specified otherwise.

If you want to contain this content within a specific section of the page, simply wrap it all in a div tag and assign a percentage width. You can then use "margin: 0px auto;" on that div to center align it.

I believe this is what you're trying to achieve. Please confirm if this solution works for you.

Answer №3

If you're not concerned about older browser compatibility, the flex model is a great option for this scenario.

Check out this example

/*layout */

body {
  margin: 0;
}
.wrapper {
  height: 100vh;
  display: flex;
  flex-flow: column;
}
.container {
  flex: 1; /* Use flex to fill remaining space and allow scrolling */
  overflow: auto;
}
/* styling */

.container {
  background: pink;
}
img[src*="grass"] {
  width: 100%;
  vertical-align: top;
}
footer {
  background: #86B31C
}
<div class="wrapper">
  <header><!-- any height -->
    <img src="https://www.ecobin.com.au/skin/frontend/ultimo/default/images/footer_grass.jpg" alt="" />
  </header>
  <div class="container">
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
      survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </div>
  <footer>footer content of any height
    <br/>come here</footer>
</div>

note Make sure to set a min-height on the wrapper or max-height on the footer/header to prevent them from taking up the entire window height on smaller screens. Also, avoid the container from shrinking down to zero height ;)

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

Make sure that the input field and label are aligned side by side in the

Is there a way to arrange the following HTML in the specified layout? <div> <div> <label>Counterparty</label> <input id="paymentsApp-inpt-cpty" ng-model="selectedPaymentCopy.counterparty" ng-required="true" ...

When the state changes, initiate the animation

Currently, I am working with Vue.js and need to animate a navigation menu. My goal is to display two li elements when a user hovers over one of the navigation buttons. At the moment, I have set the data type showActivities to false by default and changed ...

The website on iPad automatically zooms in upon opening and then increases the zoom level even further when a specific button is tapped

I recently coded a website using html, css, and js. It seems to work perfectly on all devices except for the iPad. Interestingly, when I use the iPad emulator in Google Chrome, everything appears normal. However, when I open the website on an actual iPad, ...

Tips for parsing information contained in a cdata tag using python

I have successfully used Beautiful Soup to extract CDATA from an HTML page, but now I need to parse the contents and save them in a CSV file. Here is the code I am using: from bs4 import BeautifulSoup from urllib.request import urlopen import re import c ...

Employing data retrieved from an ajax response as a json object

As a newcomer to ajax and Jquery, I am attempting to display my database graphically using c3.js. However, I am facing challenges with utilizing my ajax response in a JavaScript variable. Below is the JSON response from response.php: [{"time":"2014-05-20 ...

Looking for a fully customizable event and booking calendar?

Currently, I am searching for a unique event and booking calendar that provides the ability to customize each cell or day with our desired content. While most calendars only allow for inputting events as text, we require a solution that enables us to add ...

Trigger a function by clicking on a radio button using MVC architecture and JQuery

I am currently working on implementing a click event for two radio buttons. When one of the radio buttons is clicked, I want it to trigger an action that will render a partial view. Here are my radio buttons: <p> <input id="SelectedInterestRate" ...

Changing an element in an array by using a specific input

With the usage of either JavaScript or Jquery, I possess an array that has been arranged in accordance with Start Date (coordinates): [{ elem: '<div id="task7">', startDate: 864, endDate: 999, order: 0 }, { elem: '<div id ...

What causes text inside a fieldset to sometimes appear bigger when viewed on mobile devices?

Have you ever noticed a strange quirk in Chrome that you couldn't quite explain? I recently stumbled upon a peculiar "feature" while using fieldset with responsive design. It seemed that the text within the fieldset appeared disproportionately larger ...

Choose the option in real-time with Jquery

I'm currently developing a dynamic HTML for Select Option as seen below: item += "<td class='ddl' style='width:40%;'>"; item += "<select>" item += " <option id='list' name='selector' value=" + se ...

Alter attribute with an impact

I am looking for a solution to switch the image source using attr, while also incorporating a fade effect in the process. I have attempted to implement one of the suggestions from another post, but it is not producing the desired outcome. Current Appearan ...

Combining PDFs after successful AJAX request

I am currently working on creating multiple PDF invoices and I want to combine them into one file for easier printing. To achieve this, I have the following jQuery code: $('#printinvoice').click(function(){ $.ajax({ type:"POST", ...

Activate CSS modules in ReactJS by incorporating a .module extension to the CSS file

Being new to ReactJS, I recently learned about enabling CSS modules and discovered the following: If you append .module to a class name, it will generate a base64 hash string for that class As an example, I created a function-based component called Lay ...

How can I combine an ordinary image and a CSS2D image in THREE.js CSS2DRenderer and save them together as a single .jpg file?

After implementing the following code... (1) I successfully saved regular rendered THREE.js scenes as .jpg files; (2) Additionally, I managed to utilize CSS2DRenderer to display CSS2D labels on top of the canvas; (3) Now, my goal is to save the image wi ...

Setting background colors for classes based on an array

I have a total of six div elements on a single page, all sharing the same class. My goal is to give each one a unique color from an array I have prepared. I want to avoid any repetition of colors among these divs. Currently, I have managed to assign backg ...

CSS for when the mouse hovers over an element

Two php files and a js file are involved in this scenario. The issue at hand is that when the div is clicked, it navigates to a new page with an appended # to the URL, causing it to scroll to the specified comment ID. However, instead of scrolling to the c ...

When a specific JavaScript function is triggered, the value of an HTML control will reset to its original default value

I have a form with a specific requirement. I need to allow users to input data in a text field and press enter, which should dynamically create new controls like another text field, a dropdown menu, and another text field using jQuery. While the functional ...

Creating a Perfect Arc with a Consistent Fixed Focal Point

Trying to achieve a unique sunflower effect on canvas with an arc, but my geometry skills are a bit rusty. To begin, I set the origin point in the middle of the canvas as (X1, Y1). Then I determine the Mouse Position as (Xm, Ym). If I draw an imaginary l ...

How to use Javascript to toggle a popup containing an autoplaying Vimeo video

I am looking to create a pop-up window containing a Vimeo video inside. I have a div on my webpage with an id of "showVideo". When this div is clicked, I want to display a pop-up (new div with the id of "opened-video"). The "opened-video" div contains an i ...

The arrangement of CSS code is crucial for it to work properly; any deviation from the correct order

I am facing a problem where I am trying to display a circular div using CSS, but it only works if the background image property is set first. Typically, this wouldn't be an issue if the image wasn't being dynamically inserted using PHP code. I ...