The display property in CSS can be used to make a table fill out the horizontal space without

I am facing a challenge with floats inside two containers. I need the containers to wrap around the floats while maintaining a minimum height of 100% for both of them (container>another container>floats).

I attempted using minimum height, however, it seems that minimum height requires a parent with an exact height, not a minimum one. This approach only worked for the outer container.

Using display:table with 100% height on the containers seems to achieve what I need, ensuring they are at least 100% tall but can stretch if the content is longer.

The issue I am encountering:

Display:table is affecting the width of the containers. I cannot set the width to 100% because I need to later define their width with margins. I want them to behave like typical divs, occupying all available horizontal space.

Is there a solution available for my dilemma?

http://jsfiddle.net/Ka3TT/2/

My code:

<html>
    <body>
<div class="enclose2">
<div class="enclose1">
<div class="float">
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>
Float<br>

</div>
<div class="float">Float</div>
    <div class="float">Float</div>
</div>
</div>
</body>
</html>​

My CSS:

.float {
    width:100px;
    border:solid 1px black;
    float:left;
}
.enclose1, .enclose2 {
 height:100%;
display:table;
    background-color:#ccc;
}    
body, html {
    width:100%;
    height:100%;
}

Answer №1

To achieve a layout where three columns are aligned and expand to the same height, you can try using the following CSS code:

.float {
border:solid 1px black;
float:left;
height:100%;
width:29%;
margin-left:20px;
}
.enclose1, .enclose2 {
height:100%;
display:table;
background-color:#ccc;
width:100%;
}    
body, html {
width:100%;
height:100%;
}

This code allows the columns to fill up the available space horizontally while maintaining equal height. You may need to adjust the widths and margins to achieve the desired layout, especially if the enclose divs are within a wrapper. Feel free to experiment with the widths and margins of .float and enclose classes to customize the layout to your needs.

Alternatively, if you prefer to have fixed 100px width on the floats and expand the enclose classes horizontally, you can use the following CSS:

.float {
width:33%;
border:solid 1px black;
float:left;
}
.enclose1 {
height:100%;
display:table;
background-color:#bbb;
width:800px;
margin:50px;
}   

body, html {
width:100%;
height:100%;
}
.enclose2 {
height:100%;
background-color:#ccc;
display:table;
}  

If you only want the enclose classes to expand horizontally while keeping the floats fixed at 100px width, consider placing the entire layout in a wrapper with a width of 100%, adding padding, and setting the enclose class to width: 100%. This will allow the enclose classes to expand horizontally without affecting the fixed width of the floats.

Apologies for the lengthy explanation, but it is essential to consider the final layout goal when designing the CSS structure. Feel free to customize the code to best suit your design requirements.

Answer №2

If I understand your intention correctly, you could achieve the desired effect by using the CSS property display: table-cell instead of floating the element. This will ensure all blocks have the same height regardless of content.

For a demonstration, you can visit: http://jsfiddle.net/AmazingWebDev/Ks7HJ/9/

You may want to consider renaming the class for better clarity...

.floating-block {
    width: 120px;
    border: solid 1px black;
    display: table-cell;
}

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

Determining the exact position of an absolute element within a Bootstrap container

In my design, I am using a full-width cover image with a bootstrap container class containing an absolutely positioned image on top of the cover image. My goal is to have this image positioned exclusively on the right-hand side of the container. Below is ...

How can I adjust or eliminate the offset in Bootstrap 3 for smaller devices like tablets and smartphones?

Within the structure of my web app view (created in Rails 5), this is the main div: <nav class="navbar navbar-inverse navbar-fixed-top" > my navigation bar </nav> <div class="col-md-6 col-md-offset-3"> the central content of my web ...

Interactive checkboxes within a classic ASP webpage

I'm encountering an issue while generating checkboxes dynamically on a .asp page. Within a table cell, I am utilizing the following code (note - rsMaint is a recordset): <% if not rsMaint.EOF then rsMaint.moveFirst index = 1 %> ...

Mixing together an array of colors, experimenting with adding a touch of transparency

Here is my first question, diving right in. I recently created a canvas in HTML and followed a tutorial to generate random floating circles that interact with the mouse position......if you want to check it out, click here. The issue I'm facing now ...

At what point are DOMs erased from memory?

Recently, I've been working on an application that involves continuous creation and removal of DOM elements. One thing I noticed is that the process memory for the browser tab keeps increasing even though the javascript heap memory remains steady. To ...

Web Development: Custom Search Form

I am looking to create a website with a form similar to this one, but I'm struggling to figure out how to incorporate all three components into a single form using only HTML and CSS - no javascript. Do you have any suggestions or advice on how to achi ...

Utilize jQuery setInterval to dynamically add and remove classes on elements

My goal is to display my image in a way that resembles waving flames. I decided to achieve this effect by using two layers (flame tongues) stacked on top of each other in the same position. My initial approach was to hide one flame tongue while showing the ...

toggle visibility of <li> elements using ng-repeat and conditional rendering

I have an array of color IDs and codes that I'm utilizing with ng-repeat in the <li> tag to showcase all colors. However, I only want to display colors where the color code is less than 10, hiding any colors where the color code exceeds 10. Addi ...

Position the text in the exact center of an HTML element using absolute positioning

Hey there! I am currently working on a website and I'm trying to create a simple delete button that can be used throughout the site. However, I'm having trouble getting it positioned correctly... Here's what I have so far: <button id="c ...

Having trouble making alerts or confirmation dialogs function in JavaScript

EDIT: Many thanks to everyone who helped fix this issue (: Your help is greatly appreciated! I've been struggling to get the alert, confirm, or prompt functions to work properly in my code. Here's a snippet of the code that's causing troubl ...

Troubleshooting issue with CSS in Django_tables2

Working with the django_tables2 plugin for the first time has been an interesting experience. I followed the installation and quick start guide provided in their documentation. After pip-installing django-tables2, adding 'django_tables2' to my ...

Retrieve the bounding rectangle of a div that has the CSS style `display: contents` using the getBoundingClientRect

My objective is to apply styling and obtain the bounding box of an entire "row" within a CSS grid, including features like highlighting when hovering over it. To achieve the styling aspect, I make use of the display: contents property, so that the styles ...

Ensure that the next iteration of .each() does not begin until all nested functions have finished executing

Is there a way to ensure that my .each() function waits for all nested functions to complete before moving on? Here is the code I am working with: HTML: <div> <p>Text 1</p> <p>Text 2</p> <p>Text 3</p> & ...

Incorporate a platform-specific button in a user interface with React Native

I need to display a button that is only shown on iOS, not on android. I have tried using the following style, but it doesn't seem to be working. ...Platform.select({ android: { display:'none', }, The code for my button is: <Bu ...

Leveraging JQueryUI for an audio Seek feature, and dynamically connecting a fresh slider to the <audio> element whenever a song is swapped out

Thanks for taking a look at my question. The code snippet can be found HERE. I'm in the process of creating an audio player to handle multiple songs on a single page using JQueryUI Slider and HTML5 Audio, with one Audio element and several sliders. ...

Using JQuery to Execute Matching Based on Text Within <A> Elements

After reviewing the resources on Jquery Extract URL from Text and jquery match() variable interpolation - complex regexes, I am still a bit confused. The issue at hand is that I have a webpage with a dropdown menu at the top. Inside the dropdown, there ...

Button click initiates DataTables search rather than manually entering text in the input field

I am exploring the option of relocating the search function from an input to a button for a table that has been modified using DataTables. Currently, I have a customized input that triggers this function: <script> $(document).ready(function() { ...

Possible conflict between CSS and JavaScript on Magento website

Problem Description: Visit this link for more details I am facing an issue with the product upload process when using certain attributes. It appears to be related to a positioning problem. Despite trying various solutions, such as removing the position at ...

Mastering image focus with javascript: A comprehensive guide

On my HTML page, I have two images and a textbox. I want the focus to shift between the images based on the first character entered in the textbox. For example, when the user types '3', the first image should be focused, and for '4', th ...

Use JavaScript to swap out images

How can I change the image arrow when it is clicked? Currently, I have this code snippet: http://codepen.io/anon/pen/qEMLxq. However, when the image is clicked, it changes but does not hide. <a id="Boton1" class="button" onClick="showHide()" href="j ...