Creating visually appealing tables with nested tables using CSS for styling including borders and backgrounds

Looking to create webpages that have a variety of tables, including a main table with a header (marked 2 on the picture) and several data tables for the user (marked 1 on the picture). To style these specific data tables, I've added some custom CSS:

.datatable {
    border-collapse: collapse; /* hides double lines between cells */
    border: 2px solid white; /* hides table borders */
}

.datatable th, td
{
     padding: 5px 10px;
     border: 1px solid black; /* adds border for th and td */
}   

.datatable th {
    background-color: #EBECEC;
    font-weight: bold;
    vertical-align: bottom;
}    

.datatable tr:nth-child(odd) {
    background-color: #EBECEC;
}

The tables styled with .datatable look good in the browser. However, the main table containing these data tables also has borders around its cells, which were not present before (due to the border="0" property). How can I fix this issue and control the properties of the main table?

It seems like the browser is inheriting the styles from the .datatable class and applying them to the upper-level table or cells. Any suggestions on how to resolve this would be appreciated.

You can view the codepen here: https://codepen.io/gzbqqfbl-the-encoder/pen/QWqrBxP

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

Answer №1

Below is the CSS code to remove borders from the first column of the first row in a table:

table:first-child tr td:first-child { border: none;}

Here is the same code within a snippet:

<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta charset="utf-8" />
  <title>Dietonline Service. Результаты расчета потребности в основных пищевых веществах и энергии </title>
  <link href="style.css" rel="stylesheet">
  <style>
    html,
    body {
      background-color: White;
      font-family: rubik, sans-serif, san-serif;
      font-size: 14 px;
    }
    
    table.datatable {
      border-collapse: collapse;
      /* hiding double lines between cells */
      border: 2px solid white;
      /* hiding border of a table */
    }

    .... (content truncated for brevity) ...

    table:first-child tr td:first-child {
      border: none;
    }
  </style>
</head>

.... (remaining HTML content not touched for clarity) ...

</body>
</html>

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

Bootstrap table exceeds the boundaries of the smartphone screen

I'm currently working on my first laravel project with bootstrap (https://getbootstrap.com/) and I've encountered an issue related to mobile device responsiveness. The problem arises when using a basic table in bootstrap4 (the absence of the res ...

Bootstrap modal fails to appear on the screen

I am in need of assistance. I have a bootstrap template with a footer, and I am trying to integrate a modal. However, when I click the modal button, the modal does not appear. Is there a missing plugin that needs to be added to my template? <script sr ...

Conceal a certain element in development using CSS

Is there a way to hide the footer section from my webpage without affecting the rest of the content? For example, using something like: "div class="poweredby" display: none", but I'm unsure of the correct method... Here is the spe ...

What is the best way to choose all the options in a drop-down menu using Selenium Webdriver?

Currently, I am working with Selenium WebDriver and utilizing Java. In my application, there is a dropdown menu named Product containing multiple values (for example: 60). When running the code, I first deselect all options and then select the specific opt ...

Importing pixi-sound in the right way for PIXI JS

I have a question regarding the proper way to import pixi-sound into my project. I am facing an issue with the following code snippet: import * as PIXI from "pixi.js"; import PIXI_SOUND from "pixi-sound"; const EFFECT_SOUNDS = [...list of music] for (le ...

Unable to remove the vertical dropdown menu padding issue in Firefox

issue: https://i.stack.imgur.com/qisVn.jpg My website appears correctly on IE, Opera, and Chrome, but in Firefox, there is a spacing problem between each image in the dropdown menu. I suspect the issue lies within the CSS code. The same spacing issue occ ...

Having trouble loading a CSS file in CodeIgniter?

I've added a link to my header.php and despite trying various solutions from stackoverflow, it still isn't working for me. Can someone please help? Thank you in advance :) Here's my folder structure: Main Folder: ci_attl - application ...

Custom property fallback values do not function properly with CSS Variables

I defined a custom property in the :root selector as shown below, but for some reason my color is not rendering correctly. Can someone please help me identify what I am doing wrong? :root { --color-primary: var(--color-primary, #ffc107); } body { ...

Identify and correct improper or invalid HTML closing tags in Visual Studio Code

As part of my transition to Visual Studio Code from Adobe Brackets, I am looking to replicate the feature that highlights incorrect close markup in my code. This feature is particularly helpful in identifying duplicated </div> tags like shown in the ...

Firebase monitors the authentication status of a user

Trying to maintain a global state in my application based on whether the user is logged in or not has me puzzled. Should I only have a single onAuthStateChanged() in my JavaScript file to monitor state changes and manipulate HTML elements like account deta ...

The Bootstrap dropdown functionality is not working properly and fails to open when clicked

Can anyone help with this Navber code issue? <nav class="navbar navbar-expand-lg navbar-light" style="background-color: #FDFEFF;"> <div class="collapse navbar-collapse justify-content-center" id="navbarNav"> <a class="navbar-brand" ...

Creating a disabled HTML button that reacts to the :active CSS pseudo class

CSS: button:active { /* active css */ } button:disabled { opacity: 0.5; } HTML: <button disabled="disabled">Ok</button> After clicking the button, the browser applies the button:active state to give the appearance of a click, despite the ...

"Unable to get elements by tag name using the getElementsByTagName method in

function updateLayout() { var para = document.getElementsByTagName("p"); para[0].style.fontSize = 25; para[1].style.color = "red"; } <p>Text in paragraph 1</p> <p>Text in paragraph 2</p> <p>Text in paragraph 3</p& ...

Dynamic content alongside a stationary sidebar that adjusts in width

Attempting to create a switchable sidebar (toggling between short and long form) using bootstrap, multiple examples, and online resources. The width of the sidebar changes when toggled, and I want the content to appear next to it regardless of its length. ...

Discover how to utilize Firebug in Java to access a node's CSS properties

Is there a way to access all properties (CSS, etc) of web page nodes using Firebug within Java code without relying on XPath? I would like to retrieve all available properties instead of checking for them individually. Any advice on how to achieve this? ...

How can the presence of a CSS rule prevent another from being applied?

My attempt to create this HTML file in Chrome posed some challenges: <style> br { }​ [required] { border-width: 3px; border-color: red; } </style> <input required /> The entire content of the file is shown above. However, I noti ...

Tips for sending an email without using MAILTO in JavaScript or jQuery

Today is a great day for many, but unfortunately not for me. I've been struggling with this issue for over two weeks now and can't seem to find a solution anywhere on the internet. Stack Overflow always comes to my rescue when things get really t ...

Harnessing the power of the Zurb Foundation 4 grid system to create visually appealing list elements

When it comes to styling the layout of a page, Foundation 4's grid system with its mobile-first approach is a no-brainer, especially if you're already using other foundation elements like textual content, images, and sidebars. On the example pag ...

Enhancing accessibility: the use of sr-only or aria-label

According to MDN: In this scenario, a button is designed to resemble a standard "close" button, featuring an X in the center. Since there is no visual cue indicating that the button closes a dialog, the aria-label attribute is utilized to provide this i ...

Website issues being displayed by Internet Explorer

Greetings! Let me begin by saying how wonderful this page is - I have already found many answers here before. Please forgive any errors in my English :) In my efforts to optimize my website for SEO and increase its speed, I made several changes. The site ...