Adjusting the alignment of table cell contents without the use of JavaScript or external CSS files is necessary

I need help creating a table that resembles the design shown in the image below. I want each td cell in the outer table to have a number at the top right with a border, and text at the bottom left without a border:

https://i.sstatic.net/1YTkR.png

Currently, my code involves embedding tables within each cell to achieve this layout. However, I'm facing issues with applying borders only to the top right numbers as seen in the example image.

This is the CSS code snippet I am using:

<style>
    caption {
        font-size: 15px;
    }

    table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        border-spacing: none;
        width: 100%;
    }

    td,
    th {
        border-collapse: collapse;
        text-align: center;
    }

    th {
        border: 1px solid black;
        padding: 8px;
    }

    td {
        padding: none;
        border: 1px solid black;
    }

    td .celltable tr td{
        border:none;
    }
    table tr td  .celltable > tr:first-child td:nth-child(2) {
        border-collapse: collapse;
        border: 8px solid black;

    } 

And here's the structure of the table:

<table id="tab1">
    <thead>
        <caption><b>Table 1:</b> Transportation Problem.</caption>
    </thead>
    <tbody>
        <tr>
            <th colspan="2" rowspan="2" style="border:none;"></th>
            <th colspan="5">Destinations</th>
        </tr>>
        ...
        (Content continues with more table entries)
        ...
    </tbody>
</table>

Is there a way to selectively remove borders from all cells except the top right one in the inner tables, while keeping the overall border structure intact? Alternatively, do you recommend a better alternative to using nested tables for alignment?

Answer №1

Here is a suggestion for your code:

caption {
    font-size: 15px;
}

table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    border-spacing: none;
    width: 100%;
}


td,
th {
    border-collapse: collapse;
    text-align: center;
}

th {
    border: 1px solid black;
    padding: 8px;
}

td {
    padding: none;
    border: 1px solid black;
}
table table th, table table td {
  border: none;
}

table table tr:first-child td:nth-child(2) {
  border: 1px solid red;
}

td .celltable tr td{
    border:none;
}
table tr td  .celltable > tr:first-child td:nth-child(2) {
    border-collapse: collapse;
    border: 8px solid black;

} 

Do you want only the second cell of the first row in the inner table to have borders? Take a look at this link for reference: JSBin

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

Enhancing Your Website with Multiple Background Images in CSS3

Having trouble understanding how to position multiple background images with CSS3. I'm struggling to get them to display at the top, middle, and bottom of the page. Can you help me figure out how to make an image appear at different positions using a ...

I am encountering a problem while performing JavaScript validations

In jQuery or using the element's ID, I can validate a textbox. For example: var field = document.getElementById('tbxSearchField').value if (field == "") {alert("please enter text");} The HTML code is as follows: <input class="input" id ...

Utilizing the dynamic pairing of Three.js and CSS3 to bring life to animated 3D objects

I am currently working on a project that involves creating 3D Lego elements and assembling them into a figure using animation. I have successfully modeled the elements in Blender and exported them as .obj/mlt files without any issues. However, when it come ...

summoning the iframe from a separate window

In my current setup, I have a link that passes a source to an iframe: <a href='new.mp4' target='showVideo'></a> <iframe src='sample.jpg' name='showVideo' ></iframe> However, what I would lik ...

Unable to interact with a button element of type="button" using Selenium, but successful with elements of type

In my attempt to interact with the webpage, I am specifically focusing on this button: <button class="button-text-like marg-l-0 float-l desktop-only remove-button" data-bind="click: $root.removeCartItem" type="button"> <i class="gicon-cross">& ...

Is there a way to render an image onto a canvas using an input tag?

Looking to create an image preview using canvas? Upload the image with the input tag and watch it display on canvas. I've experimented with various methods such as using img tags, setting img src for canvas using img tags, and trying onclick function ...

The backtick is not functioning correctly when trying to append the result in the Internet Explorer browser

I am using the .html method to append HTML content to a specific div ID within my file. <html> <head> Title <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> </head> <body> ...

Position the label to float on the right side and be centered vertically

I have successfully implemented a navigation bar, but I am facing an issue where the 'menu toggle' button does not align on the right side of the screen when the screen width is 768px or less. Instead, it appears right after the image. (Refer to ...

When it comes to using brackets and HTML, I keep receiving an error message indicating that there is no index file

I'm having trouble with this code - it works fine in Code Academy, but I am new to HTML and trying to practice outside of the platform. Every time I try to live preview in Brackets, I get an error message saying "make sure there is an html file or tha ...

Ensuring Proper Tabulator Width Adjustment Across All Browser Zoom Levels

<div id="wormGearTabulatorTable" style="max-height: 100%; max-width: 100%; position: relative;" class="tabulator" role="grid" tabulator-layout="fitDataTable"><div class="tabulator-header" role="rowgroup"><div class="tabulator-header-co ...

"Using jQuery to append a new div after the last div that matches a specified class on

I am looking to dynamically add a new div element at the end of the last match on click. <form id="form"> <div class="border item-block"> <p><b>Color :</b> silver </p> <input type= ...

How can you convert an epoch datetime value from a textbox into a human-readable 24-hour date format

I have an initial textbox that displays an epoch datetime stamp. Since this format is not easily readable by humans, I made it hidden and readonly. Now, I want to take the epoch value from the first textbox and convert it into a 24-hour human-readable da ...

Require this form to be centered flawlessly

<form class="form-horizontal" role="form" id="contactf" action="http://titan.csit.rmit.edu.au/~e54061/wp/form-tester.php" method="post"> <div class="form-group"> <label class="control-label col-sm-2 lb" for="email">Email : </ ...

Masonry is limited to displaying a single column at a time

Struggling to make masonry work for the first time, as it is only displaying as a single column. Being more of a designer than a developer, it's possible that I'm overlooking something. Here is the code snippet I'm using: <body> ...

The fields in the row of the Rails form_tag are overly spacious

My login form in Rails 4 with Bootstrap 3 is giving me trouble. It doesn't format well on any device, especially smaller screens where it becomes unusable. I suspect the huge right margin of the rows is to blame, but I can't figure out the root c ...

Show or hide a fixed position div using jQuery when clicked

I am new to jQuery and I am trying to create a "full page menu" on my own. However, I am struggling to hide the menu on the second click. I tried using .toggle() but I found out that it has been deprecated. Can someone assist me with this? Thank you so muc ...

CSS Class Returns to Inactive State

One of my tasks involves adding a new class to an image. .bbbLink img { outline: 1px solid #ddd; border-top: 1px solid #fff; padding: 10px; background: #f0f0f0; } When hovering over the image, I apply the following styles, .bbbLink img ...

Is there a way to make text within a Div selectable even if it is positioned behind another Div with a higher z-index?

Currently grappling with some code, unfortunately cannot easily paste the problematic part here as I am unsure of its exact location. Here's the situation: there is a div containing text that needs to be selectable, however, there is another div with ...

Aligning Checkbox Labels for Web Forms

Can an image convey more than a thousand words? I'm looking to align the second (and following) lines with the first one. Any suggestions? Html stands for <input><span>text</span> ...

When TTF fonts are installed on the device, they take precedence over Google fonts

I have successfully implemented the Ubuntu font from Google Fonts on my website: <link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,300italic,400italic,500,500italic,700,700italic' rel='stylesheet' type='text/css ...