Creating an HTML table layout: A step-by-step guide

I am in need of assistance with designing an HTML layout.

My goal is to display 3 columns for each table row as described below:

Column #1 will contain text only.

Column #2 will have an inner table, which may consist of 1 or 2 rows depending on the contents of Column #3.

Column #3 will contain multiple rows, each listing the name of a food item. Healthy items should be listed first, followed by any unhealthy items. If there are only healthy items, Column #2 will display a single row with the word "HEALTHY" in it. Otherwise, both "HEALTHY" and "UNHEALTHY" will be displayed in separate rows.


Column #2       Column #3
HEALTHY         Apple
                Pear

Or it could appear as follows:


Column #2       Column #3
HEALTHY         Apple
                Pear
UNHEALTHY       Coffee crisp
                Chocolate milk

Both Column #2 and Column #3 should have grids (border top/bottom) for each row.

What would be the best way to implement this?

Please note: The row borders in Column #2 must align with those in Column #3.

I hope my explanation was clear enough.

Answer №1

I'm not entirely certain about your specific query, but let me try to address it:

<table cellpadding="0">
    <tr>
        <td>Column A</td>
        <td>Column B</td>
        <td>Column C</td>
    </tr>
    <tr>
        <td rowspan="4">Content for Column A goes here</td>
        <td rowspan="2">CATEGORY 1</td>
        <td>Item X</td>
    </tr>
    <tr>
        <td>Item Y</td>
    </tr>
    <tr>
        <td rowspan="2">CATEGORY 2</td>
        <td>Item Z</td>
    </tr>
    <tr>
        <td>Item W</td>
    </tr>
</table>

Here is some pseudo code to help you generate the table structure:

for each item in column-B
{
    for each sub-item in item.column-C
    {
        <tr>
            if sub-item is the first in item.column-C
            {
                if item is the first in column-B
                {
                    <td rowspan="total-number-of-items">Content for Column A goes here</td>
                }
                <td rowspan="number-of-items-in-column-C">itemtext</td>
            }
            <td>sub-item-text</td>
        </tr>
    }
}

Add CSS to apply top and bottom borders:

<style>
table
{
    border-collapse: collapse;
}
td
{
    border-top: solid 1px black;
    border-bottom: solid 1px black;
}
</style>

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

Is optgroup malfunctioning in IE 10?

My main question is: does optgroup not function properly in IE? The Plnkr code works fine in Chrome but encounters issues in IE 10. I'm trying to find a solution that will work across both browsers. Is this a known problem? In Chrome, I can expand/co ...

Is my website broken due to Internet Explorer?

The progress on my current website project has been smooth so far, but I'm encountering an issue when testing it in Internet Explorer. Whenever I try to view it in IE, the layout breaks completely. You can check it out at . I've attempted using C ...

Having trouble uploading multiple input files in a Flask and HTML form

I'm attempting to upload multiple files using HTML in my Flask application. Below is the HTML form I have been using: <form action="url", method="POST", enctype="multipart/form-data"> <font size="2"> File2: <input type= ...

When utilizing ng-content alongside *ngtemplateOutlet, the content does not appear visible within the DOM

I'm working with three Angular components - a base component and two child components (child1 and child2). The structures are as follows: child1.component.html <ng-template #child1Template> <div> <h1>CHILD 1</h1> ...

Achieving perfect centering in PrestaShop using CSS for both horizontal

Hello there, I require assistance with aligning some images in the center of my Prestashop webpage. I am specifically struggling with aligning 3 circular images at the bottom of the page (not social icons). I cannot figure out how to properly center these ...

Issues with Hovering over Button Contained in Slider

I can't seem to figure this out. It should be a simple fix. I have 5 slider images with black buttons that link to different galleries. I want the button background color to change on hover, but it's only working on one of the sliders. It seems ...

Tips for utilizing javascript document.createElement, document.body, and $(document) in an HTML web resource for Microsoft CRM code reviews

Let me start off by saying that I am not a regular blogger and I am feeling quite confused. If my question is unclear, please provide guidance for improvement. I recently submitted a Microsoft CRM PlugIn to the Microsoft Code Review. I am new to Javascrip ...

Retrieving table information using curl and regular expressions

Here is the code I have developed to extract data from a table on a specific website. However, I am looking to remove any links present in the data and also separate the title and price into an array. <?php $ch = curl_init("http://www.digionline.ir/ ...

How to Implement Flexbox Display Across Various Browsers Using jQuery?

Running into an issue here. I'm trying to switch from display: none to display: flex, display: flex-box, and display: -ms-flexbox but for some reason it's causing errors in my code.. Here's what I've been working on: $(elem).css({&apos ...

Updating a class within an AngularJS directive: A step-by-step guide

Is there a way to change the class (inside directive) upon clicking the directive element? The current code I have updates scope.myattr in the console but not reflected in the template or view: <test order="A">Test</test> .directive("test", ...

Stop jQuery ajax from running any JavaScript code contained in a script or HTML response

As stated in the documentation: If html is specified, any embedded JavaScript within the retrieved data will be executed before returning the HTML as a string. Similarly, using script will execute the pulled back JavaScript before returning nothing. Is ...

The correct way to reference images in the resources folder using a URL in CSS

After I generated a Maven dynamic web project using an archetype, I decided to organize the javascript, css, and image folders under the webapp folder. The structure now looks like this: myproject | main | | | java | | | resources | | ...

Experiencing difficulties with utilizing height percentages for CSS divs

Despite encountering similar issues with others, I am still unable to resolve the problem on my own. Your assistance is greatly appreciated. Currently, I am developing a guestbook in PHP using an HTML template. The issue I am facing is that the div elemen ...

Unable to assign default value to input field of type "time" in Chrome browser

I'm intrigued by Chrome's feature that automatically applies masking/formatting when using the type="time" attribute/value. However, I'm having trouble setting an initial value for the control. For example: <input type="ti ...

Activate a specific component of hover effect within multiple components generated by the `v-for` loop

Hey there! I'm currently facing a CSS challenge related to Vue. Let's say I want to display multiple components using v-for, and I want to add a hover effect to each component individually. The goal is to have the hover effect only apply to the c ...

Customizing Images using a JSON array of images

Looking to implement a feature that displays images fetched from a CMS via a JSON file. The JSON data structure is as follows: { "images": [ {"title": "Image One", "url": "image1.jpg"}, {"title": "Image Two", "url": "image2.jpg"}, {"title": "Ima ...

The background image on mobile devices is excessively zoomed in

My RWD page is experiencing a strange issue with the background image. The image has the following styles: #background-image { width: 100%; height: 100%; opacity: 0.5; position: absolute; z-index: -1; background-image: url('../landing.jpe ...

What is the best approach for designing a UI in Angular to showcase a matrix of m by n dimensions, and how should the JSON format

click here for a sneak peek of the image Imagine a matrix with dimensions m by n, containing names on both the left and top sides. Remember, each column and row must be labeled accordingly. ...

"Creating a custom navigation bar with full width and navigation corners on both left

I am struggling to make my website's navbar stretch to the edges of the container while maintaining full width. I have added left and right padding to each navigation item, but in smaller laptop resolutions, the items break onto a new line, which is n ...

'OR' separated by the <hr> tag

This particular code functions correctly on the Firefox and Chrome browsers. However, there seems to be an issue with IE and Opera, where the 'OR' text is only visible within a 2px height area. hr { height: 2px; border: 0; background-color ...