Ensure that the floating divs are positioned at the bottom of their parent element

Encountering a common issue in a particular scenario... Attempting to automatically adjust the height of floating divs to ensure they reach the bottom of their parent.

For instance: http://jsfiddle.net/k95nK/1/ The objective is for all floating columns to have equal height and touch the bottom of the container. (Therefore, all columns should match the height of the one with the most content) The parent's height cannot be predetermined. The contents must determine the parent's height dynamically.

.content {
width : 150px;
background-color : #123456;
float : left;
margin-right : 10px
}

#allcontent {
background-color : #90c89a;
}

#allcontent:after {
content:"";
display: table;
clear: both;
}


<div id="allcontent">
    <div class="content">hello</div>
    <div class="content">hello</br>hello</div>
    <div class="content">hello</div>
</div>

I understand such solutions are frequently sought after, (How to get a div to resize its height to fit container?) but I am struggling to find a resolution for my specific case.

Attempts using absolute positioning have caused them to exist outside the document flow...

Answer №1

To achieve the desired layout change, you should remove the float:left property and instead apply the display:table-cell property to your content div.

.content {
width : 150px;
background-color : #123456;
display:table-cell;
border-right:10px solid #90c89a;
}

Check out the DEMO here

Answer №2

To ensure proper layout, it is important to specify a height for the main container and then set the inner div height to 100%. Here's how you can achieve this:

#maincontent {
    background-color: rgb(112, 180, 138);
    height: 280px;
}
.inner-content {
    background-color: rgb(28, 62, 96);
    float: left;
    height: 100% !important;
    margin-right: 15px;
    vertical-align: top;
    width: 170px;
}

UPDATE:

If you prefer not to use fixed heights, you can create spacing between the div elements using borders or padding like so:

.inner-content {
    background-color: rgb(28, 62, 96);
    display: table-cell; /* **** APPLY THIS STYLE **** */
border-right: 25px solid rgb(112, 180, 138); /* **** Using border with matching color for spacing **** */
    margin-right: 15px;
    width: 170px;
}

Answer №3

When utilizing floats, you are limited to two options.

1) Specify a fixed height for all elements

.section {
    height: 200px
}

Check out an example on jsfiddle: http://jsfiddle.net/8yT76/4/

2) Resort to using tables

While using tables may solve the issue easily, it is considered outdated in modern web development practices.

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

Display multiple videos next to and below one another in a responsive layout

I am attempting to display multiple Vimeo videos responsively alongside and below each other. I have noticed that when using the embed-responsive feature, the videos may not align perfectly if different videos are used. However, they align perfectly when t ...

Dividing a button within a flex container

I'm currently building a contact form and I applied display:flex to its div. All the fields are showing up properly and dynamically resizing, except for the submit button which always gets cut in half. Shouldn't it behave like the rest of t ...

why is it that I am not achieving the expected results in certain areas of my work?

I am facing issues with getting an alert response from certain buttons in the code. The AC button, EQUALS button, and the button labeled "11" are not behaving as expected. I have tried troubleshooting but cannot identify the problem. Can someone please ass ...

Sibling div positioned below the main div

I have a container div with two child divs inside. The first child div has a fixed width, but its height depends on the content (a message box). Right next to it on the same line, I want another div (displaying the time) to be at the bottom of the parent d ...

Display the dropdown selection

I am trying to customize my dropdown menu so that when I hover over the main menu item (Sample Page), only the About submenu is displayed, not all of the dropdown menus. li.menu-item.dropdown .dropdown-menu { position: absolute; top: 70px; visibil ...

Place the written content within a spinner on a Bootstrap framework

I have successfully implemented a Bootstrap 4.3 spinner on my website, but I am encountering an issue where I want to add additional text below the spinner. Here is the HTML code I am using: <div class="d-flex justify-content-center"> <d ...

Can someone assist me with arranging these divs within my flexbox layout?

I'm having a tough time figuring out why the flex box aspect is making things so complicated for me. My goal is to achieve responsiveness like this - https://i.sstatic.net/MdzPO.png Despite following various flex tutorials, I haven't been succe ...

Alter the CSS of a particular ul li tag using jQuery when hovering over it

Just starting out with jQuery and struggling to accomplish my goal. Need to work with HTML only as the server doesn't support PHP or Ruby, and I'm still learning those languages. Working with the latest jQuery version 1.10.2. My issue involves a ...

Differences in React projects utilizing materialize-css compared to those using react-toolbox or material-ui

Is there a difference in technical benefits or code reliability when directly using material-css in JSX versus utilizing JSX specific libraries like material-ui or react-toolbox? Conversely, could using JSX libraries like material-ui or react-toolbox provi ...

The jquery accordion title width does not align with the content width when an icon is included

Is there a way to adjust the widths of the heading and div elements after adding edit and delete icons to match the standard accordion style? Thanks <div id="accordion"> <h3><a href="javascript:;"> ...

Unable to make a div grow within a Popper component in a React.js application

I'm facing a challenge with implementing a CSS feature and need some assistance. https://i.stack.imgur.com/KXpGd.png Upon clicking the "See link options" button, the content loads but spills out of the popper. My goal is to have the popper expand in ...

Learn the simple trick to switch to full screen by just clicking

import { Component, OnInit, ElementRef } from '@angular/core'; declare var JQuery : any; @Component({ selector: 'app-presentation', templateUrl: './presentation.component.html', styleUrls: ['./presentation.c ...

Are there any strategies to bypass the color limitations in Bootstrap 5?

Recently, I began studying bootstrap through a crash course video tutorial. The developer demonstrated using various predefined color classes like danger, warning, and primary. Curious, I wondered if it would be possible to substitute dark with tomato re ...

"Enhancing the aesthetics: Stylish blue borders around Bootstrap

After successfully setting up bootstrap-select, I have noticed that blue borders are showing in two specific instances: 1) within the dropdown menu 2) when a new value is selected I have made some adjustments but the issue persists. Can someone please p ...

Unable to prevent ordered lists from overlapping with other content I attempt to place beneath them in HTML

function filterImages() { let input = document.getElementById('searchbar').value; input = input.toLowerCase(); let images = document.getElementsByClassName('gallery'); for (let i = 0; i < images.length; i++) { ...

The IntroJs step is only partially visible on the screen

Currently, I am incorporating introJS into my application and encountering an issue where one of the steps is only partially visible on the screen. Despite trying various position settings such as auto, left, right, etc., this particular item consistentl ...

Using CSS alone, design a stunning horizontal divider

If you're looking to recreate a similar effect using CSS alone, check out this CSS fiddle I've put together. hr.fancy-line { border: 0; height: 1px; background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(215,215,215 ...

Modify the static navigation menu to a dynamic menu in Wordpress

Currently, I am attempting to transform my static navigation menu into a dynamic WordPress navigation menu. This is the code that I currently have: <nav> <ul id="menu"> <?php $pages = array( 'in ...

How can I make an element begin sticking to the page at 50px when scrolling, and then stop sticking at 2000px?

I am looking for a solution to position an image relative or absolute initially, then make it stick after some scrolling, and finally return it to its original behavior before transitioning to another section on the page. I've tried using this script ...

What is the best way to flip cards with the onClick event in JavaScript?

My cards are currently facing down with the code* provided. What steps should I take to flip them face up using onClick functions? Furthermore, how can I store the IDs in an Array and use them to retrieve images from my image collection? HTML <table s ...