Eliminate the table background in a single cell

Apologies if the title is not very descriptive, I couldn't find the right words to use. Below is the table in question.

https://i.sstatic.net/LHwbG.png

I'm looking to remove the white border (background of the table) from just the upper-left cell. I still want the white background between the other cells, but not in that specific cell. Here's an example of how I want it to appear.

https://i.sstatic.net/ELJNj.png

My initial idea was to add a ::after pseudo-element to that cell with some border or padding to cover the gap between the cell and the page background, but I'm unsure of how to implement this. Any suggestions?

Below is the CSS used on this page.

    body{
        background: #C3DEF2;
        font-family: Noto Sans, Roboto, Helvetica, Arial, sans-serif;
    }
    
    table{
        background: white;
        table-layout: fixed;
    }
    tr:nth-child(even){
        background: lightgray;
    }
    td{
        padding: 20px;
    }
    td.corner{ /* cell in upper-left corner */
        background: #C3DEF2;
    }
    
    .head1{ /* top row */
        text-align: center;
    }
    .head2{ /* leftmost column */
        text-align: right;
    }
    .head1, .head2{
        background: lightblue;
        text-transform: uppercase;
        font-weight: 600;
    }

As requested, here is some HTML related to this part of the table.

<table id="the_table" width="100%>
<tbody>
    <tr class="head1">
        <td class="corner"></td>
        <td><a href="https://stackoverflow.com">Candidate 1</a></td>
        <td><a href="https://stackoverflow.com">Candidate 2</a></td>
    </tr>
    <tr>
        <td class="head2">Education</td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td class="head2">Election Reform</td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td class="head2">Environment</td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td class="head2">Foreign Policy</td>
        <td></td>
        <td></td>
    </tr>
</tbody>
</table>

More importantly, where does the border come from? It seems to be the white background of the table, but what exactly causes that space between the cells?

Answer №1

Below is a simple and effective solution:

Your HTML code should look like this:

<table>
    <tr>
        <td style="border: 1px inset white;">1</td>
        <td>2</td>
        <td>3</td>
    </tr>
    <tr>
        <td>4</td>
        <td>5</td>
        <td>6</td>
    </tr>
    <tr>
        <td>7</td>
        <td>8</td>
        <td>9</td>
    </tr>
</table>

For CSS, use the following code:

table {
    margin: 20px;
    border-collapse: collapse;
    border-spacing: 0;
}

td {
    width: 40px;
    height: 40px;
    border: 1px solid black;
    text-align: center;
}

td:hover {
    border: 1px solid red;
}

Check out the working demo here:

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

The anchor tag seems to be malfunctioning within the div container

<style type="text/css> .xyz { position: absolute; top: 120px; left: 160px; z-index: -1; } #container { position: relative; overflow: visible; opacity: .3; } </style> <body> <div> <video i ...

What is the process for programmatically aligning two cards side by side using Material UI in React after retrieving data from an API?

I am currently working with data from an API that I need to display in the format of cards, arranged side by side. To achieve this, I have been using an array and passing the data to components programmatically. You can see the output image and my code bel ...

Display a div upon loading with the help of Jquery

Two divs are causing me trouble! <div id="loader"> </div> and <div id="wrapper"> </div> "The wrapper div is not located inside the loader div just to clarify." This is my code: $(window).bind("load",function() { $(&apos ...

The display: flex property is not being properly implemented in Tailwind CSS for the sm:flex

I have a div with the following styles <div class="hidden sm:visible sm:flex"> .... </div> The sm:visible style is applied like this @media (min-width: 640px) .sm\:visible { visibility: visible; } However, the property disp ...

What is the best way to superimpose text on a variety of images with varying sizes using CSS

I have a client who is requesting a sold text to be displayed on top of all images that have been sold, positioned in the bottom left corner of each image. While I have successfully implemented this feature, the issue arises when dealing with images of var ...

Inserting a border both above and below an element may result in the parent overflowing

I am facing an issue similar to the following: div.parent { height: 100px; padding: 20px; box-sizing: border-box; overflow: auto; } div.parent div.thing { height: 20px; width: 90%; border: 1px solid black; } <div class="parent"> ...

Ensuring that images are the perfect size for their parent container

Exploring the functionalities of angular bootstrap carousel, I am eager to showcase various images and enable clicking on them. The challenge I'm facing is that my images are not uniform in size and don't fit perfectly within my bootstrap column ...

"To ensure consistent alignment, position list items with varying heights at the bottom of the

Is there a way to align a series of li items to the bottom of their parent, the ul, without using any unconventional methods? The challenge lies in the fact that these li items need to have a float: left property and vary in height and width. Below is my ...

JQuery Mobile header style vanishing when applied to a page generated dynamically

My second page retrieves data from an Ajax call on the home page, but the header lacks JQuery styling and I suspect a connection between the two. Here is the HTML for the dynamically generated page: <div data-role="page" id="breakdownDialog" data-add-b ...

During DragAndDropToObject in Selenium IDE, the initial element in the list is overlooked

I have a webpage that is split into two datagrids. The left datagrid is structured like this: <ul class="left_dg"> <li> <ul></ul> </li> <li> <ul></ul> </li> <li&g ...

What are some key considerations for creating a website that is optimized for printing?

I am working on creating a website filled with content that I want to optimize for printing. My goal is to have the content easily printable without any unnecessary elements like navigation or advertisements. To achieve this, I am considering using two sep ...

Ways to customize the appearance of the Next/Prev Button in Griddle

Here is the scenario that has been implemented: nextClassName={'text-hide'} nextText={''} nextIconComponent={ <RaisedButton label='Next' />} As a result, a Next Button with a wrapper div above the but ...

I'm encountering an issue with the "z-index: -1" property in React

After creating a form placed alongside buttons, I encountered an issue where the form overlaps the buttons and prevents them from being clicked. Despite setting the z-index to -1, it seems that the form remains clickable even when not visible. Research ind ...

Navigating Through Secondary Navigation with Ease

In my React project, I am developing a mega-menu styled dropdown navigation. As a functional component, I am utilizing the useState hook to manage the state and control the display of sub-navigation items. The functionality of the dropdown is operational, ...

Adapting CSS styles according to the height of the viewport

Goldman Sachs has an interesting webpage located here. One feature that caught my eye is the header that appears as you scroll down, with squares changing from white to blue based on the section of the page. I'm curious about how they achieved this ef ...

Styling Text with CSS

I am currently using axios to fetch data from my backend. The data consists of a string format similar to "phone number: {enter phone number here}". My goal is to add CSS styling wherever there is a curly brace. let testString = "hello this ...

Can you choose the class that has not yet been seen before?

Imagine a scenario where the following code is present: <div class="a"> <div>1</div> <div>2</div> <div> <div> <div class="b">3</div> </div> ...

Eliminating Unnecessary Stylesheets in Vite and Vue Website

When working on the Vite-Vue application, I noticed that the styles I implemented for both index.html and Vue components/views are showing up as crossed out in the browser. Additionally, many of the styles I added to the components/views are also being cro ...

Retrieve main page elements from an additional page called PageSlide

I have implemented the jquery PageSlide plugin as a menu feature on my website. The plugin opens a separate page on the side of the main page to function as a menu. However, I am facing a challenge in accessing the main page's elements from this side ...

What could be causing the malfunction in my JavaScript random selector?

Can anyone assist me with this issue? I'm attempting to implement JavaScript functionality to highlight randomly selected picks that I input, but it's not functioning correctly. Every time I inspect my JS code on the webpage, I encounter an erro ...