Tips on aligning three divs horizontally within a container while maintaining a height of 100%

UPDATE: The alignment has been corrected by adding floats. However, the height still doesn't fill 100%. Check out the new look: Image Link

In my footer container, I want to arrange 3 columns (colored green, white, and red for clarity). Currently, they are stacking vertically, but I aim to have them side by side with a height of 100% to match the container's height. Here is the current layout: Current Layout

Each column has a width of 33% to adhere to responsive design principles. I have already removed padding and margins from all div elements.

Your assistance in achieving this layout would be highly appreciated. Thank you.

HTML:

<div id="Page">

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

        </div>      

        <div id="footer">
            <div id="footerContainer">
                <div id="footerLeft">
                    <p>
                    Test
                    </p>
                </div>
                <div id="footerCenter">
                    <p>
                    Test
                    </p>
                </div>
                <div id="footerRight">
                    <p>
                    Test
                    </p>
                </div>
            </div>    <!-- footerContainer -->
        </div> <!-- Footer -->

    </div> <!-- Page -->

CSS:

#content {
    background-color: black;
}

.wrapper {
    width: 60%;
    height: 100%;
    margin: 0 auto;
}

#footer {
    position: absolute;
    width: 100%;
    height: 300px;
    background-color: black;
}

#footerContainer {
    width: 60%;
    max-height: 100%;
    margin: 0 auto;
}

#footerLeft {
    width: 33%;
    height: 100%;
    float: left;
    background-color: darkolivegreen;
    padding: 0;
}

#footerCenter {
    width: 33%;
    height: 100%;
    float: left;
    background-color: white;
    padding: 0;
}

#footerRight {
    width: 33%;
    height: 100%;
    float: left;
    background-color: firebrick;
    padding: 0;
}

Answer №1

Make the following changes to improve the styling of the footer:

#content {
    background-color: black;
}

.wrapper {
    width: 60%;
    height: 100%;
    margin: 0 auto;
}

#footer {
    position: absolute;
    width: 100%;
    height: 300px;
    background-color: black;
}

#footerContainer {
  display: flex;
    width: 60%;
    height: 100%;
    margin: 0 auto;
}

#footerLeft {
    width: 33%;
    background-color: darkolivegreen;
}

#footerCenter {
    width: 33%;
    background-color: white;
}

#footerRight {
    width: 33%;
    background-color: firebrick;
}
<div id="Page">

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

        </div>      

        <div id="footer">
            <div id="footerContainer">
                <div id="footerLeft">
                    <p>
                    Test
                    </p>
                </div>
              <div id="footerCenter">
                    <p>
                    Test
                    </p>
                </div>
              <div id="footerRight">
                    <p>
                    Test
                    </p>
                </div>
            </div>    <!-- footerContainer -->
        </div> <!-- Footer -->

    </div> <!-- Page -->


Here is a simplified version with improved CSS styling for the footer:

#content {
  background-color: black;
}
.wrapper {
  width: 60%;
  height: 100%;
  margin: 0 auto;
}
#footer {
  position: absolute;
  width: 100%;
  height: 300px;
  background-color: black;
  display: flex;
  justify-content: center;
}
#footer > div {
  width: 20%;
}
#footerLeft {
  background-color: darkolivegreen;
}
#footerCenter {
  background-color: white;
}
#footerRight {
  background-color: firebrick;
}
<div id="Page">

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

  </div>

  <div id="footer">
    <div id="footerLeft">
      <p>
        Test
      </p>
    </div>
    <div id="footerCenter">
      <p>
        Test
      </p>
    </div>
    <div id="footerRight">
      <p>
        Test
      </p>
    </div>
  </div>
  <!-- Footer -->

</div>
<!-- Page -->


For compatibility with older browsers, use the following CSS styles for the footer:

#content {
  background-color: black;
}
.wrapper {
  width: 60%;
  height: 100%;
  margin: 0 auto;
}
#footer {
  position: absolute;
  width: 100%;
  height: 300px;
  background-color: black;
}
#footerContainer {
  display: table;
  width: 60%;
  height: 100%;
  margin: 0 auto;
}
#footerContainer > div {
  display: table-cell;
  width: 33%;
}
#footerLeft {
  background-color: darkolivegreen;
}
#footerCenter {
  background-color: white;
}
#footerRight {
  background-color: firebrick;
}
<div id="Page">

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

  </div>

  <div id="footer">
    <div id="footerContainer">
      <div id="footerLeft">
        <p>
          Test
        </p>
      </div>
      <div id="footerCenter">
        <p>
          Test
        </p>
      </div>
      <div id="footerRight">
        <p>
          Test
        </p>
      </div>
    </div>
    <!-- footerContainer -->
  </div>
  <!-- Footer -->
  <!-- Footer -->

</div>
<!-- Page -->

Answer №2

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#container {
    width:100%;
    height:100%;
} 
#div1 {
    width:33%;
    display:inline-block;
    float:left;
    height:100%;
}
#div2 {
    width:33%;
    display:inline-block;
    height:100%;
}
#div3 {
    width:33%;
    display:inline-block;
    float:right;
    height:100%;   
}
</style>
</head>
<body>
<div id="container">
<div id="div1"><!--
--><div id="div2"><!--
--><div id="div3">
</div>
</body>
</html>

Ensure that the second div is properly aligned by adjusting the #container text-align property to center. Remember to utilize comments to remove any extra spacing between the divs.

Answer №3

Apply the float: left property to all 3 elements simultaneously.
Combine the selectors using commas without repeating the properties.

To expand the elements, modify max-height to height in the CSS rule for #footerContainer.

#content,
.wrapper {
  background-color: black;
}

.wrapper {
  width: 60%;
  height: 100%;
  margin: 0 auto;
}

#footer,
#footerContainer {
  position: absolute;
  width: 100%;
  height: 300px;
  background-color: black;
}

#footerLeft,
#footerCenter,
#footerRight {
  float: left;
  width: 33%;
  height: 100%;
  padding: 0;
}

#footerLeft {
  background-color: darkolivegreen;
}

#footerCenter {
  background-color: white;
}

#footerRight {
  background-color: firebrick;
}
<div id="Page">

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

  </div>

  <div id="footer">
    <div id="footerContainer">
      <div id="footerLeft">
        <p>
          Test
        </p>
      </div>
      <div id="footerCenter">
        <p>
          Test
        </p>
      </div>
      <div id="footerRight">
        <p>
          Test
        </p>
      </div>
    </div>
    <!-- footerContainer -->
  </div>
  <!-- Footer -->

</div>
<!-- Page -->

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

Create a Boxplot chart using Chart.js that dynamically adjusts the minimum and maximum values to allow for additional space on either

I am utilizing chartjs v2.9 for creating a boxplot and my code structure is as follows: function generateRandomValues(count, minimum, maximum) { const difference = maximum - minimum; return Array.from({length: count}).map(() => Math.random() * ...

Head styles for tinyMCE

When viewing the tinyMCE example on the official website using Firefox, you may notice the editor blinking. This issue seems to only occur in Firefox, possibly due to external CSS files for the editor. I am considering adding all CSS rules directly into th ...

Is it possible to achieve a height transition using CSS instead of relying on JavaScript

I created these custom cards using a combination of HTML, CSS, and JavaScript. However, I've noticed that the height transition animation is not as smooth as I'd like it to be, especially on certain pages. Is there a way to achieve this animation ...

Sorting by price using the ng-repeat directive is not suitable for this

Utilizing angular's ng-repeat along with orderBy on a product catalog page to sort the products based on a select change. The ordering by name using orderBy works as expected, however, when it comes to price it sorts like this: 1,10,11,12,13,14,2,3,4 ...

Having a floating left <UL> list with floating right text boxes positioned below the UL list instead of being set next to it

I'm attempting to align an unordered list on the left and a group of textboxes on the right within a div tag. The problem I'm facing is that the text boxes are positioned below the list items instead of being adjacent to them. .PersonLI { flo ...

Eliminate any undefined data in the popup map of Javascript

I am working with JSON data that is being displayed in a pop-up on a map. In cases where there is missing data (Visibility), the word undefined appears in the pop-up. Is there a way to remove the undefined text so that it does not show up in the pop-up? ...

Tips on arranging JSON elements based on the sequence of another JSON

Currently, I am facing a challenge with sorting a list of parks (park_list) based on both distance and area. The code snippet below successfully sorts the list by distance: sortList(index){ return function(a, b){ return (a[index] === b[index] ? 0 : ...

I am struggling to grasp the concept of how the g flag in JavaScript's string.match(regexp) method operates

In the JavaScript book "The Good Parts", there is an explanation of the method string.match(regexp): The match method works by comparing a string with a regular expression. Its behavior varies based on whether or not the g flag is present. Without the g ...

Using jQuery/AJAX for nested functions, as well as utilizing the Clone and Cufon properties

Currently utilizing Cufon to easily transform fonts into canvas. This script specifically transforms H1 headers: Cufon.replace('h1', { fontFamily: 'SuperMegaArial2010' }); While everything is functioning correctly, I encounter an is ...

What is the best way to place a 3D model at random points on the surface of a sphere while ensuring that it always faces the right direction?

I'm faced with the challenge of placing huts randomly on a spherical world. While this task is feasible, the issue arises when the huts do not sit correctly - their bottom should be in contact with the tile below. I've experimented with the &apos ...

How to fetch and display images using Vue.js with Axios and a web API

I have managed to successfully upload an image using axios and can preview it in Postman. However, I am unsure of how to proceed with rendering the image in vuejs. Implementing the Get Method: public HttpResponseMessage FetchImage(int id) { ImageServ ...

Get the JS file by tapping the download button, and access the

In creating the web page, I utilize a modular approach. Leveraging node js and the node-static server are essential components of this process. One specific requirement I have is implementing file downloads from a computer to a device using a button trigg ...

What is the best way to optimize a search for objects with extensive field arrays?

Recently, I've been working with an object schema that includes an array field to store ids for objects from a separate collection. This array has the potential to contain thousands of ids. Up until now, I have been excluding this field using .select( ...

Searching by multiple parameters in Angular.js

I have a script that scans through a field and highlights the words related to the search input. I want this script to not only filter by title, but also by name. How can I adjust the code to filter both the title and name when searching? <li ng-repeat ...

Reverse animation transition not activating in CSS

In an attempt to create a side navbar using HTML/CSS, I implemented hover animations where hovering over an icon would cause it to double in size and disperse the rest of the items in the navbar. While I successfully achieved this animation with JavaScript ...

JS/PHP: No error message will be alerted

<script type="text/javascript"> $(function() { $("#continue").click(function () { $.ajax({ type: "POST", url: "dbc.php?check=First", data: {full_name : $('#full_name').val(), usr_email : $('#usr_ema ...

Identifying Master Page Controls Post-Rendering

Within my asp.net projects, I have noticed a discrepancy in the control id on the master page's Contentplaceholder1. On my local server, the id appears as "ctl00_Contentplaceholder1_control" after rendering. However, when the application is deployed t ...

When using the post method in jQuery, it may send data that is unspecified in the request body

Greetings to everyone and I hope you have a fantastic start to the new year. I've been attempting to operate an API on localhost that will store input data in MongoDB. The issue arises when attempting to send data using the post method. The request ...

Click event in jQuery to change the background color of <td> element

I'm still getting the hang of jQuery, so please bear with me. :) The purpose of this code is to color a square with the selected color when clicked if it's white, and turn it back to white if it's already colored. It works fine except for a ...

How can I log an object definition and text in the same console.log statement?

Looking for a way to correctly display "obj" in the same string as "note." Here's my JavaScript code: console.log(obj);// [query: "wordOfTheDay"] console.log(note + " : " + obj ); // obj does not show up I want to ensure that "obj" displays properly ...