CSS Table with Adjacent Single-Cell Row Restricting Multi-Cell Column Width

Hey there! I'm working on designing a website layout using CSS and divs that must meet the following criteria:

  1. The top and bottom elements should take up 100% width
  2. The top element should be a single "table-cell"
  3. The bottom element needs to be divided vertically into 2 "table-cell" sub-elements, all fitting neatly under the Top element with no gaps or overlapping

It seems like a simple task with table-styled divs, but I've been tinkering for hours trying to stop the bottom element from inheriting its width from the leftmost cell in the top element. Can anyone give me some guidance?

Here's a link to my jsfiddle

Just a heads up - the "STUFF" cell is causing issues by pushing the second column of the next row to the right, preventing the elements from aligning properly underneath the top row.

HTML:

<div id="dvStructure_Outer">
    <div id="dvStructure_Upper">
        <div id="dvUperrCell">
            STUFFSTUFFSTUFFSTUFFSTUFFSTUFFSTUFFSTUFFSTUFFSTUFFSTUFF<br />
        </div>
    </div>
    <div id="dvStructure_Lower">
        <div id="dvDetailStructure_Left">
            Lower Left<br />
        </div>
        <div id="dvDetailStructure_Right">
            <div class="dvDetailSection">
                Lower Right Right Detail 1<br />
            </div>
            <div class="dvDetailSection">
                Lower Right Right Detail 2<br />
            </div>
            <div class="dvDetailSection">
                Lower Right Right Detail 3<br />
            </div>
        </div>
    </div>
</div>

STYLE

#dvStructure_Outer {
    display:table;
    min-width:500px;
    border-color:red;
    border:solid; 
}
#dvStructure_Upper {
    display:table-row;
    border:dashed;
}
#dvStructure_Lower {
    display:table-row;
    border:dashed;
}
#dvUperrCell {
    vertical-align:center;
    display:table-cell;
    border:dashed;
}
#dvDetailStructure_Left {
    display:table-cell;
    border:dashed;
}
#dvDetailStructure_Right {
    display:table-cell;
    width:400px;
    border:dashed;
}
.dvDetailSection {
    display:table-row;
    border:dotted;
}

Answer №1

When comparing HTML tables to CSS tables, it's important to note that CSS tables do not support column or row spans. To work around this limitation and create a top row that spans the width of the bottom cells, additional CSS table nesting was necessary.

For a clearer illustration, check out this JSFiddle Example: http://jsfiddle.net/TalkingRock/pewywx4y/. You'll see how the top row now occupies the full width of the table.

A book by Sitepoint titled "Everything You Know About CSS is Wrong" delves into CSS table layouts and acknowledges:

CSS tables do not support concepts like row or column spanning, which can complicate using a single layout structure compared to HTML tables. However, nested CSS tables can achieve similar results.

HTML

<div class="table short-width">

<div class="table-row">
<div class="table-cell green"><p>Top Row</p></div>    
</div>

<div class="table-row">
<div class="table-cell">    
<div class="table full-width">
<div class="table-row">    
<div class="table-cell peach"><p>Bottom Row Left</p></div>
<div class="table-cell purple"><p>Bottom Row Right</p></div>      
</div>
</div>    
</div> 
</div> 

</div>

CSS

.table {display:table;}
.table-row {display:table-row;}
.table-cell {display:table-cell;}
.short-width {min-width:500px;}
.full-width {width:100%;}
.green {background-color:#ccffcc;}
.peach {background-color:#ffcccc;}
.purple {background-color:#ccccff;}
p {margin:0; padding:.5em;}

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 default way to toggle content in rows using Material UI?

Currently, I am utilizing Muitables and have a query regarding how to set the expanded rows to be displayed by default, similar to the illustration below: Upon initial page load, it is preferred for the content in that row to automatically expand (arrow d ...

Having trouble with vertical centering in Bootstrap 4 - need assistance

I tried to center text vertically on my webpage using a code snippet that I found, but it didn't work for me. Here is the HTML code I used: <html lang="pl"> <head> <meta charset="utf-8"> <meta name="viewport" content="wid ...

The HTML/CSS Progress Bar appears on the browser but does not appear when attempting to print the document

I am currently assisting a friend with creating a resume and we wanted to include a visually appealing progress bar for the skills section. After successfully implementing the progress bar and seeing it display correctly in the browser, we encountered an ...

Is it possible to adjust the background image with properties like Scale to Fill, Aspect Fit, or Aspect Fill?

Is it possible to set the background image using the following properties in HTML? (These are properties used for iOS images, but I am unsure if there are similar ones in HTML): Scale to Fill, Aspect Fit, Aspect Fill https://i.stack.imgur.com/5X83I.jpg ...

Vue.js: click event does not trigger transform animation

I am facing a challenge with rotating an arrow icon within a dropdown menu. Despite my efforts, the rotation does not synchronize with the appearance of the dropdown menu. Here is the Vue component code snippet: <nav> <section class= ...

Struggle to link a string together effectively for proper concatenation

I'm currently working on a project that involves utilizing the Wikipedia API. My goal is to create a link for each list item, but I'm encountering difficulty with proper concatenation. Here's the code snippet I'm using: for (var j=0 ...

Tips for activating a tooltip upon clicking instead of hovering over it:

I am currently working with tooltips and I am looking to display the tooltip message upon clicking, rather than on hover. Is there a way to make this modification? This is the code I have so far: .tooltip { position: absolute; top: 7px; margin-l ...

Adjust the height of the image using CSS while maintaining its aspect ratio within the Gall-Peters projection

I've implemented a Gall-Peters projection on my website and I'm looking for the right CSS code to maintain its aspect ratio. I want the image to take up 100% of the available width without elongating the countries' shapes. Can anyone help wi ...

Ways to retrieve an element from another HTML file?

I am facing a challenge in my current project where I need to extract information from an external HTML document without embedding the entire page using <iframe>. I want to create a new HTML document for each product in my e-commerce site, and then r ...

What is the best way to define coordinates or set margins for the autoTable component in jsPdf when using React js?

While working with the jsPdf library to create a PDF in React, I am encountering an issue where I am unable to set margins for the autoTable when there are multiple tables on a single page. Below is the code snippet: import React from "react"; ...

The beauty of Aurelia's scoped CSS

Embarking on my Aurelia journey, I find myself navigating through the vast world of web development with tools like nodejs, gulp, and more. The Aurelia CLI has made it convenient for me to set up a visually appealing Aurelia project in Visual Studio Code ...

Do not apply transitions to a pseudo-class in CSS

Can a pseudo-class with the same property as another pseudo-class be prevented from being transitioned? Take a look at this example code: button { height: 50px; width: 150px; font-size: 20px; color: white; border: none; background-color: b ...

The specified MIME type (text/html) is not compatible with stylesheets

When attempting to link a css file to my express-handlebars file, I encountered the following error: The style from 'http://localhost:4000/cs366/style/draft.css' was refused due to its MIME type ('text/html') not being a supported st ...

How can we show pictures when a user clicks?

After creating a model for displaying images in a modal when clicked by the user, I encountered an issue. Whenever I try to access the images from the gallery within the modal content, it only displays a blank popup. I want the pictures from the image gall ...

How can I open a new window, redirect the current one, and bring focus to the new window using JavaScript?

Trying to troubleshoot a problem I'm having with the following setup: - Using SAP Portal, I am launching an HTML page containing this code. - The goal is for the HTML page to open a new window. - Once the new window opens, the original HTML page ...

I'm having trouble with my Typescript file in Vscode - every time I try to edit the css code, all the text turns red. Can someone

Check out this visual representation: [1]: https://i.stack.imgur.com/9yXUJ.png Followed by the corresponding code snippet. export const GlobalStyle = createGlobalStyle` html { height: 100%; } body { background-image: url(${BGImage}); ba ...

How can I display an image from PHP on another page?

I need to display multiple images from a database on the index.php page interface. <?php while($row = $result->fetch_assoc()) { ?> <table border="1" width="702" height="149" align="center"> <tr> <td width="148"><img sr ...

What is the process for incorporating a button to the left of the search field?

Is it possible to enhance the search field by adding a button to make it more user-friendly? Below is the code I have been using: <div id="search"> <div class="container"> <h1>Search U.K. house price data</h1> <form c ...

Guide on triggering a function with the Enter key in Angular 9

A button on my Angular component currently triggers a method with a (click) event, but I also want the same method to be triggered if the user presses the enter key in the input box. This gives the user flexibility. Below is the HTML code for the input an ...

Is there a way to activate the window load event within this Jest test scenario?

I'm in the process of setting up my first Jest test for DOM manipulation and jQuery in my Rails project. Right now, I'm facing a basic challenge of ensuring that imported JavaScript functions are functioning as expected. In order to tackle this ...