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

The robot will automatically update its own message after a designated period of time

I am facing an issue with my code where the bot is not updating its message after a specific time period defined by time.milliseconds * 1000. How can I make the bot edit its message after that duration? let timeout = 15000; if (author !== null && ...

Font that has been downloaded is not showing up on the HTML document

I recently downloaded a new font and ensured the file location is correct, but for some reason it's not working: <style> @font-face { font-family:"myfont"; src: url('fonts/Helvetica85Heavy_22449.ttf'); } h1 { font-family: ...

How to modify this to return a function and eliminate the need for declaring a function

Greetings! I understand that this may seem simple to some of you, but I am feeling quite lost. I've been tasked with removing the function declaration and converting it into a return function. Any assistance would be greatly appreciated. const canView ...

The program encountered an unexpected identifier 'getProject' instead of ';'. It was expecting to find a semicolon after the async variable declaration

When using this JavaScript on a webpage, I encounter an issue: <script async type="module"> import {projectCode} from "./assets/js/config.js"; import {getProject} from "./assets/js/saleproject.js"; import {getAccount} fr ...

Error: The variable is not declared in the AJAX/JQuery code

I'm encountering an issue with my code that involves grabbing HTML from an AJAX request. I am trying to hide one row of a table and show another based on the response, but for some reason, the variable holding the HTML content seems to disappear when ...

Comparing two tables in jQuery/Javascript for matching data

I want to check for matches between the rows of two HTML tables, where the data in the first cell can be duplicated but the data in the second cell is always unique. The goal is to determine if the combination of values in the first and second cells of tab ...

What is the best way to delay a recursive JavaScript function for 3 seconds?

Before writing this post, I have already come across the following questions: how-to-pause-a-settimeout-call how-to-pause-a-settimeout-function how-to-pause-a-function-in-javascript delay-running-a-function-for-3-seconds Question The below code snipp ...

Guide on converting HTML datetime picker datetime-local to moment format

I am looking to convert an input type : <input type="datetime-local" name="sdTime" id="stTimeID" onChange={this.stDateTime} /> into a specific date format: const dateFormat = 'MM/DD/YYYY hh:mm:ss a'; To achieve this, I need to transfer ...

PHP XML loop encountering issues with functionality

Hi there, I'm a newcomer to stackoverflow, but I've been following this site for quite some time. Currently, I'm working on a simple web application that will serve as a catalogue for music tracks, allowing users to add their own tracks afte ...

The asynchronous request sent to the API action in MVC does not trigger the success event (ASP.NET Web API)

The response from the API action is shown here. I have written a web API action as shown below and it works fine when called via an AJAX request. However, I am facing an issue where the AJAX request does not return a success result even though the action p ...

Modify the background color of each word within the search bar

I've been attempting to colorize each word using jQuery and give them a colored background. I came across a solution, but it only seems to work for the HTML content, not the input field in the search bar. Below is an example of what I found: HTML So ...

Top tips for handling HTML data in JSON format

I'm looking to fetch HTML content via JSON and I'm wondering if my current method is the most efficient... Here's a sample of what I'm doing: jsonRequest = [ { "id": "123", "template": '<div class=\"container\"&g ...

How to customize JavaFx context menu appearance using CSS to achieve a full-width background color

I am trying to customize my context menu, but I'm having trouble with the white space between the menu item and the context menu border. Here is an example: view the rendered context menu with CSS styles What I want is for the color to fill the entir ...

<ol><li>Arranges elements in a peculiar way if the image is aligned to the left</li></ol>

Explore this comprehensive presentation on combining PDFs online. In this blog post, I have encountered two instances of <ol><li> formatting. The first one is styled properly using the following CSS: .post_content ul, .post_content ol ...

Retrieval of jQuery remove() method

Essentially, I am utilizing an OnClick function to delete a DIV. Once the OnClick is triggered, it invokes the remove() jQuery function to eliminate the div. Below is my code that implements the removal using remove(): <div id="add"> <button typ ...

Can you identify the nature of the argument(s) used in a styled-component?

Utilizing typescript and react in this scenario. Fetching my variable const style = 'display: inline-block;' Constructing a simple component export const GitHubIcon = () => <i className="fa-brands fa-github"></i> Enh ...

An Alternative Approach for Executing a Function within an AngularJS Directive

I am currently working on a unique element directive that displays a user's picture and name. This directive has various configuration attributes, one of which is the uc-on-hover attribute. The purpose of this attribute is to determine what element sh ...

The list of suggestions is not populating when triggered by the 'change' event

Using the typeahead jquery plugin in Rails 4.2.4 for autocompletion of lists has a specific issue: The typeahead list only loads with custom parameters the first time; it doesn't reload the second time. Here's an example code snippet from the vi ...

Retrieve and save only the outcome of a promise returned by an asynchronous function

I am currently working on an encryption function and have encountered an issue where the result is returned as an object called Promise with attributes like PromiseState and PromiseResult. I would like to simply extract the value from PromiseResult and s ...

Switch the header from left to right movement for mobile devices

I am dealing with two headers in my layout <section> <header class="col-lg-9"> <!-- some content --> </header> <header class="col-lg-3"> <!-- some content --> </header> </section ...