Ways to place the footer in the middle of 2 divs?

Hey there! I'm currently experimenting with creating a 3 column layout and running into an issue with the footer placement. I want the footer to go between the two sidebars at the bottom, but my middle column isn't extending all the way down like the sidebars. I don't want to use margin-left as a solution because I believe there must be a better way to achieve this alignment.

https://i.sstatic.net/dOaQi.png

This is what I have so far:

<!DOCTYPE html>
<html>
<head>
    <title>First</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <header></header>

    <div id="first-column"></div>

    <div id="middle-column"></div>

    <div id="third-column"></div>

    <footer></footer>

</body>
</html>

CSS:

html, body {
    height: 100%;
    margin: 0;
}

header {
    background-color: #444444;
    width: 100%;
    height: 20%;
}

#first-column {
    width: 15%;
    height: 80%;
    background-color: #d8d8d8;
    float: left;
}

#middle-column {
    width: 70%;
    height: 70%;
    float: left;
    background-color: red;
}

#third-column {
    width: 15%;
    height: 80%;
    background-color: #d8d8d8;
    float: left;
}

footer {
    background-color: #222222;
    height: 10%;
    width: 70%;
    position: absolute;
    bottom: 0;
    margin-left: 100px;
}

Answer №1

To tackle this issue, there are multiple approaches that can be taken. One simple adjustment that can be made to ensure the layout functions properly is as follows:

Adjust the width of your left column to 15%. By changing the margin-left of the footer from 100px to 15%, all elements will align correctly.

https://jsfiddle.net/7ufL979v/

Answer №2

To avoid using margin-left, you can opt to float the third column to the right. By doing so, you can float your footer just like the other boxes, provided you remove position: absolute and margin-left.

#third-column {
    width: 15%;
    height: 80%;
    background-color: #d8d8d8;
    float: right;
}

footer {
    background-color: #222222;
    height: 10%;
    width: 70%;
    bottom: 0;
    float: left;
}

If you prefer a more contemporary approach, consider exploring flexbox. Unlike floating boxes left and right, flexbox is designed to efficiently produce layouts.

Answer №3

One option is to place it in the center column, right at the bottom.

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

What is the best method for implementing a "night mode" feature using CSS?

I have a vision for a website that offers both a 'day' and 'night mode', providing users with a light and dark version of the site. However, I'm struggling to find the best way to achieve this. Initially, I attempted creating two ...

Keep scrolling! There's no need to worry about reaching the end of the page and having to start over

I'm experiencing an issue where scrolling only works once when the page is initially loaded. I need it to be able to repeat from the beginning each time. <div class="content"> <div class="next-section blue">First Section</div> & ...

Animating a straight line between two points on a webpage using HTML5 and JavaScript

Here's a simple question that might have a solution... I am interested in creating an animation that moves between two points in a straight line, using HTML5 and/or JQuery. ctx.beginPath(); ctx.moveTo(0, 0); // starting point ctx.lineTo(100, 100); / ...

Azure Chatbot that logs conversations in Webchat whenever the user selects 'none of the above' option

Recently, I've delved into the world of web chat services and embarked on a journey to craft a chat bot using pure JavaScript code that can seamlessly integrate into any HTML file. Despite consulting Microsoft's documentation, I find myself in a ...

Why isn't the CSS pseudo ::before functioning properly on an Icon element?

I am encountering an issue with displaying a vertical line to icons in my HTML code. The structure of the HTML is as follows: Below is the HTML code snippet: <div class="newsTimePeriod item-One"> <h3>News</h3> ...

What is the best way to ensure that the closing </a> tag remains on the same line while all other tags are placed on a new line in a Vue

vue/html-closing-bracket-newline is causing an unexpected space after the link text, leading to conflicts and errors in prettier and eslint. I am searching for a straightforward configuration change to resolve this issue without resorting to individual lin ...

Conceal all table rows with the exception of the row that has been clicked

I am working on a table that uses ng-repeat to populate its rows. When a row is clicked, I am able to retrieve data related to the object using ng-click. The table gets populated with information from a JSON file. My question is, how can I make it so tha ...

Unable to create account using PHP

Every time I attempt to create an account, the data I receive is always problematic. The username must be between 3 and 15 characters I find it frustrating that the account creation never goes through successfully. What baffles me even more is that af ...

Design a navigation bar that seamlessly incorporates an image

I am struggling to achieve a seamless header design that flows from the logo. I have experimented with aligning images within containers and using long background images, but neither method has yielded satisfactory results. Is there a reliable way to cre ...

The variable in the HTML input value is not fully visible when filling out the HTML form

I am working with a Python Flask code where I have passed a dictionary to an HTML form. The table in the form correctly displays both keys and values, but when trying to populate a form field with the value from the dictionary, only the first word is displ ...

Repair copied website data in Excel spreadsheet

I'm currently in the process of extracting a large volume of data from a website. However, when I paste it into Excel, it's not in a table format and appears like this: France Europe Spain Europe Egypt Africa I'm looking for a way to str ...

Having trouble clicking the button due to the overlay blocking it?

This code contains the HTML portion <li id="nav1" class="navs"><a unselectable="on" draggable="false" class="Navigation" href="http://youtube.com">YouTube</a></li> Below is the CSS code .navs:after { content: ""; position: ab ...

Animating with React using the animationDelay style does not produce the desired effect

Is there a way to apply an animation to each letter in a word individually when hovering over the word? I want the animation to affect each letter with an increasing delay, rather than all at once. For example, if scaling each letter by 1.1 is the animatio ...

Animating pseudo-elements using Jquery

I'm having trouble animating the :after pseudo-element of my ul. Below is the CSS code I have: #slider .mypagination ul::after { content: ""; width:25%; bottom: 0; left:0; position: absolute; border-top:1px solid #7accc8; ...

Experiencing overflow due to Bootstrap form styling

Issue: While working on creating a signup form, I've encountered a problem where the screen has a slight overflow on the right side whenever there are form groups included in the form. Steps taken so far: I have utilized Chromium dev tools to identi ...

Sending a form cancellation submission within a nested function call

I need help preventing my form from submitting in case the confirmation message is cancelled. How can I achieve this within the each() loop? $('#myForm').submit(function() { var inputs = $(this).find('input:checked'); inputs.ea ...

Release date approaching, but not as anticipated

Utilizing Java servlet to construct a portion of HTML and sending it with a JsonPrimitive for display in a dialog box. Here is the code snippet: ja = new JsonPrimitive( "<a href='#' onclick='return showDueDateUpdateDialogue(" + invoice. ...

PHP - session expires upon page refresh

I'm in the process of creating a login system for my website and I've run into an issue with updating the navigation bar once a user has logged in. Every time I refresh the page, it seems like the session gets lost and the navigation bar doesn&ap ...

Obtaining user Object data from an HTML form in Spring Boot Controller

Having trouble retrieving data from an HTML form in my controller method while trying to create a straightforward Web application for user registration. I've attempted various solutions without success. Main class: /* Main class code here */ Con ...

Automatic table width expansion with CSS

I'm in the process of creating a new website, and I want the layout to resemble the following: +---+--------------+ |# | | |n | #page | |a | table.basic | |i | | |g | | |a | | |t | ...