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

How can you dynamically disable the submit button on a form in Angular 7+ based on the form's current status?

Let's consider a scenario with a button in our code: <button type="button" class="menu-button" [disabled]="isInvalidForm()">Save</button isInvalidForm() { console.log('I am running!'); return this.nameValidator.errors || this.last ...

Dropdown menu is not positioning correctly over other elements on the webpage

After researching multiple stack overflow questions and attempting various solutions, I still haven't been able to resolve my issue. Please refrain from marking this question as a duplicate. The problem I am facing is that my dropdown menu is not ap ...

Email sending through PHP AJAX can be done without refreshing the page. The email action is handled in email.php and incorporated into

I am having trouble sending this with AJAX. The error message I keep getting is: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more assistance, please visit @ jquer ...

If the value of the input matches, set the checkbox to be

I have successfully implemented functionality that allows the value of an input to be changed by clicking a checkbox. This works without any issues. Now, I am facing the challenge of automatically checking the checkbox when the page loads, but only if the ...

Include a lower border on the webview that's being shown

Currently, the webview I'm working with has horizontal scrolling similar to a book layout for displaying HTML content. To achieve this effect, I am utilizing the scroll function. My inquiry revolves around implementing a bottom border on each page usi ...

Implement a fullscreen hero image on a specific blogroll template page in Wordpress

My portfolio website uses custom page templates for each page. The blog page is not the landing page, but an interior page. I have been able to add a custom hero image to every page template except for the blog page. Currently, I am using the content.php p ...

jQuery show/hide functionality allows you to toggle the visibility of elements

I am looking to create a toggle button that expands the menu-wrapper width and hides the sidebar when clicked. Here is the initial CSS styling: #my-wrapper { Width:500px; } #sidebar-wrapper { width:200px; } Upon clicking the button, the CSS will update ...

Creating a sort button in HTML that can efficiently sort various divs within a table is a useful tool for enhancing user experience

My HTML table is populated with various <td> elements. How can I arrange these divs based on IMDb rating, TomatoMeter, etc... [ CSS code is not provided below ] <table> <tr class="row"> <td class="column"> <br> ...

Utilizing nested classes in CSS or SCSS for calling a class within another class

I am having trouble calling a class within another class. Can someone help me figure out how to do it? Here is the HTML code: <div class="main">Content</div> <div class="cover">Cover content</div> And here is t ...

Styling errors with jQuery validation

How can I remove the borders in ul > li elements? Here is my current setup: errorLabelContainer: $("ul", $('div.error')), wrapper: 'li', errorContainer: $('div.error'), I have tried the following: div.message{ backgr ...

"Key challenges arise when attempting to execute the node app.js script through the terminal due to various middleware compatibility

I'm a beginner with node.js and I've encountered an issue while trying to run my node app.js file after incorporating a new file named projects.js which contains the following JS code: exports.viewProject = function(req, res){ res.render(" ...

Horizontal compression applied to background image

After following a suggestion ("css only technique number 1" found here http://css-tricks.com/perfect-full-page-background-image/), I experimented with using an inline img element and CSS to create a background image that would occupy the entire browser win ...

The jQuery fadeToggle function toggles the visibility of an element starting from hidden instead

I'm having an issue where text in my div only appears on the second click, instead of the first. What could be causing this problem? $('#fPaperCirclePic').on('click', function () { $('#fPaperCircleText, #isargebla, #moq10 ...

Can you provide step-by-step instructions on how to customize styles with MUI in my application?

I am encountering issues with MUI while attempting to customize the color of my buttons. The two methods I have tried so far have been unsuccessful. For example, Method 1: import React from 'react' import { Typography } from '@mui/material& ...

Is there a way to bypass cells within an html table?

Creating an online board game and looking to have the cells go around the board. Wondering if anyone knows a way to skip the cells in the middle? Attempted using   but it doesn't seem to be effective. Here is a snippet of the code: #board { ...

Using jQuery to access the ID of a div and create a custom close button

I am trying to implement a close button for my popup DIVs. Each one has a unique ID and I want to hide them by setting the CSS 'display' property to 'none' when closed. However, the following example is not functioning as expected. I a ...

When the click event is triggered, the second function guess() does not execute

I am currently developing a number guessing application. It consists of two functions, the first one called startGame() works correctly (it receives the maximum number and then disappears by adding the hidden class). However, the second function that is ...

The functionality of Intersection Observer causes text to appear over the header

Hey everyone, I've been working on a scrolling animation to make text appear when it's at least 50% visible. So far, I have an animated header with an Onscroll Event and Intersection Observer for the text. It's all working well, except for ...

Displaying inline causes the block elements to be removed from the

After two months of learning HTML and CSS, I still feel like a beginner. I'm attempting to create a header navigation bar, but whenever I apply the display: inline property, everything vanishes. I know this issue is probably basic, but any advice woul ...