Different sizes of CSS tables

Creating a responsive layout involves displaying <div> boxes within a grid:

The six individual boxes on this page are placed in a row within the HTML source:

<div class="control">
<div class="controlContent">
<a>VARIABLE-HEIGHT CONTENT with potential image float</a>
</div>
</div>

The control divs allocate percentage widths to each box, enabling grouping into rows as screen size increases. The controlContent divs set properties such as padding, margin, background, and border-radius.

The challenge lies in achieving consistent height among siblings in the same row despite varying content heights due to using display: table-cell. This results in gaps beneath smaller cells where gradient backgrounds may not fully cover the cell height.

To address this issue, a need for elements mimicking table rows arises, especially when responsiveness alters grouping based on CSS media queries.

Exploring solutions utilizing anonymous table boxes or anonymous table rows leaves questions regarding implementation, particularly while employing CSS selectors like :nth-child() for managing floating boxes and potentially establishing new table rows at specific intervals.

An optimal resolution should align with best practices without relying heavily on presentation markup, ideally accommodating any number of cells within a variable-dimension table setup for responsive design.

Answer №1

display:table-cell; ensures that the div/columns have the same height, as long as the parent div is set with display:table;.

Feel free to check out this fiddle (add/remove columns as needed).


An alternative approach would be to give .control a fixed height and then apply height:100%; on controlContent.

If you wish to use percentages exclusively, you must specify a height on all the parent containers of .controlContent, up to html and body:

html, body, .control, .controlContent {
    height:100%;
}

This method is more reliable since some older browsers do not render table-cell properly.

However, keep in mind that you need to know the height (in pixels or percentage) of all containers.


Another option is the faux column technique, although it may not be suitable for your situation.


Lastly, there's the JavaScript / jQuery approach, which could look like this in your case:

$(document).ready(function(){
    var highestContent = 0;
    $('.controlContent').each(function() {
        var currentHeight = $(this).height();
        if( currentHeight > highestContent ) highestContent = currentHeight;
    }).height(highestContent);

});

This script sets the value of the tallest content to all controlContent when the page loads. It may require adjustments for different resolutions targeted by media-queries.


If I were in your shoes, I'd opt for the table-cell method to allow for varying widths at different resolutions, ensuring compatibility across modern desktop and mobile browsers. Just make sure to test it on multiple devices!

EDIT: Noticed you're using min-width media queries. Here's a suggested modification:

div.controlContent {
    /* other styles */
    display: block;
    /* other styles */
}
@media only screen and (min-width: 480px) {
    /* other styles */
    div.controlContent {
        display: table-cell;
    }
    /* other styles */
}

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

``I'm having trouble getting the onchange event to function properly in a customized

After following a tutorial, I successfully created a custom select dropdown using the provided link. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_custom_select However, I am facing an issue with the onchange event not working for the select ...

Only allow scrolling if the number of child elements exceeds a certain limit

I am looking to implement a scroll feature on the <ul> element when the number of <li>s exceeds a certain threshold. For example, if we have 12 children, I want to display only 7 of them and then scroll through the rest. This is my current app ...

Arranging various JavaScript arrays

I've been working on a script using the Haversine formula, but I'm running into an issue where it always directs me to the first location in the array, no matter how many times I switch them around. Any suggestions? var locations = new Array( ...

Creating an HTML table syntax from a PHP 2-dimensional array

I am looking for a way to extract data from a bi-dimensional array and display it in an HTML table format. Here is an example of the array: $grid = array( array(0,0,0,0),array(0,0,0,0),array(0,0,0,0),array(0,0,0,0),array(0,0,0,0)); $grid[0][0]=4;$grid[0][ ...

SVG: organizing objects based on event priority

I am struggling with layering and event handling in an SVG element. Check out the example here: https://stackblitz.com/edit/angular-ivy-rkxuic?file=src/app/app.component.ts app.component.ts import { Component, VERSION } from '@angular/core'; @ ...

The Jquery animate function is not compatible with the transform property

I am facing an issue with the Jquery animate function. Despite trying various solutions, I have been unable to get it to work. Below is the HTML code that I have used: <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

Items in the Vue.Draggable display can be arranged on both the left and right

Recently delving into Vue.js, I am utilizing Vuedraggable for item dragging in my project. Currently, the items in the draggable div are shown as Text 1 Text 2 Text 3 Text 4 Is there a way to rearrange them to display like this? Text 1 Text 2 Text 3 T ...

Deactivate the selection option in Syncfusion NumericTextbox

I have integrated an Angular NumericTextbox component from Syncfusion into my application. A problem we encountered is that when the input is clicked, it automatically gets selected. Is there a way to disable this behavior? Problem: https://gyazo.com/a72b ...

Past methods: Obsolescence alert and caution

Trying to grasp the concepts of PHP & MYSQL, I have written this code which seems to be functioning properly. However, there are several "warnings" that I am unsure about. Nonetheless, PHP successfully connects to the database. Below are the relevant codes ...

The collapsible menu located beneath my navigation bar is unable to reach the correct position on the right side

I'm attempting to create a collapsible navigation bar with its contents shifting to the right side when resized to medium size, but I'm having trouble. Can someone please assist me with this? I have also included the code below. <nav class=&qu ...

What could be causing me to receive null when trying to retrieve an element with document.getElementById, even after invoking $(document).ready(function() { ... })?

Here's a small example. I'm feeling a bit rusty with JavaScript, as it's been some time since I last worked with it. The problem I'm encountering is an error in Chrome developer tools: "Uncaught TypeError: Cannot set property 'src ...

Struggling with implementing Mobile Navigation menu

I'm struggling to implement a mobile menu for my website. After adding the necessary code, when I view the page in a mobile viewport, all I see are two sets of periods ("..."). However, unlike in the code snippet provided, the list does appear on the ...

In JavaScript/jQuery, there is a technique for retrieving the values of dynamically generated td attributes and the id tags of elements inside them within tr

I am currently working on creating a calendar of events using PHP, jQuery, and ajax. The calendar is embedded within an HTML table, where the rows and fields are dynamically generated based on the number of days in a specific month. In order to successfull ...

Disable a button during an AJAX request

Whenever a button is clicked, the record is saved to the database without refreshing the page using AJAX. I have implemented the AJAX code successfully. Now I need guidance on how to manage the state of the Submit button - enabling/disabling it dynamicall ...

I'm looking to add a price ticker to my html webpage. Does anyone know how to do this?

PHP Code <?php $url = "https://www.bitstamp.net/api/ticker/"; $fgc = file_get_contents($url); $json = json_decode($fgc, true); $price = $json["last"]; $high = $json["high"]; $low = $json["low"]; $date = date("m-d-Y - h:i:sa"); $open = $json["open"]; ...

generate a different identifier for ajax requests avoiding the use of JSON

The AJAX request functions in the following way: success: function(data) { $('#totalvotes1').text(data); } However, I need it to work with unique IDs as follows: success: function(data) { $('#total_' + $(this).attr("id")). t ...

Retrieve a particular HTML element from an object that has been mapped

After reproducing my issue on a smaller scale for easier handling, I am now aiming to implement an onclick function that reveals the hidden content inside each column. The plan is to initially hide the content using display: none and then switch it to disp ...

Firefox failing to display CSS files on web pages

My project is deployed on IIS 7.5 and when trying to access it from a different machine using Firefox, all files are rendered except for the CSS files (although they work fine in IE). I have checked that the MIME type for .css files is correctly set up in ...

What is the optimal location for storing JSON data while dynamically loading via AJAX?

Let's imagine a scenario where there is an HTML page hosting a dynamic modal box. Clicking on different links within the page triggers the modal to open, each showing different content based on the clicked link. The dialog contents are fetched using A ...

Change the background color according to the user's input text

I want to create a text box where users can input color keywords like blue, lime, or black. When they click submit, I want the background color of the page to change accordingly. This is what I have so far: <label for="color">Color: </label> ...