Is there a way to customize padding and color in HTML table cells?

I am looking to style cell d with a full yellow background in my HTML code for Outlook display. How can I achieve this?

To clarify, I am using agility HTML pack to make changes to the cell d at runtime while ensuring that the table remains well-formatted. I specifically want to add a yellow background to cell d without altering its parent td class.

Final solution: https://jsfiddle.net/0khjqdh0/

<table class="XXX" >
    <tr class="header">
        <td>Col 1</td>
        <td>Col 2</td>
    </tr>
    <tr class="d1">
        <td>a</td>
        <td>b</td>
    </tr>
    <tr class="d0">
        <td>c
        </td>
        <td> 
            <div class="special_class"> d </div>
        </td>
    </tr>
</table>



.XXX table{
    border:0px;
    border-collapse:collapse;
    padding:0px;
}

.XXX tr.header td {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10.0pt;
    font-weight: bold;
    border:1px solid #C0C0C0;
    color:#FFFFFF;
    background-color:#4F81BD;
    border-collapse:collapse;
    padding:5px;
}
.XXX tr.d0 td {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10.0pt;
    background-color:#E1EEF4;
    border:1px solid #C0C0C0;
    padding:5px;
    white-space:nowrap;
}

.XXX tr.d1 td {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10.0pt;
    background-color:#FFFFFF;
    border:1px solid #C0C0C0;
    padding:5px;
    white-space:nowrap;
}

.XXX div.special_class {
background-color:yellow;
}

Answer №2

To apply a specific style to a cell, you can assign a class to the cell itself:

<td class="custom-style">
  <div> Content here </div>
</td>

Next, define a CSS rule targeting that specific class within the table row and column:

.tableClassName tr.rowClassName td.custom-style {
    background-color: blue;
}

See demo here: http://example.com/demo

Answer №3

Experiment with using the CSS property background-color:yellow; on the parent td element, or consider reducing padding in the td cell and adding that padding to the child div instead.

Answer №4

In order to change the background-color of a specific td, make sure to assign the class directly to that td element:

<td class="unique_class">

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

Error: ExpressJs cannot locate the requested CSS file

Currently, I am delving into the world of expressJS and nodeJS in an effort to expand my skills. However, I've hit a bump in the road when the server fails to locate the CSS file (resulting in a 404 error) upon loading the HTML page. Surprisingly, the ...

Having trouble with the Three.js OBJ loader in CodePen?

Currently, I am experiencing a challenge with loading an OBJ file on Three.js. Oddly enough, the functionality seems to be working perfectly fine when I deploy the files on my server as demonstrated here: However, when attempting to run it on Codepen, I e ...

How to use jQuery to target every anchor element within an unordered list

I am trying to manipulate an unordered list structure by changing the class of the anchor tags when a specific link is clicked. For example, when the link in List Item 1 is clicked, I want to change the class of all links underneath List Item 1 to "yes". ...

What could be the reason behind the unexpected behavior of my Bootstrap 3 carousel?

I'm attempting to replicate this visual effect in my own carousel, featuring semi-transparent images on the left and right sides. However, I'm encountering a negative result with my project when transitioning between slides at : here. This is th ...

`the varied significance of e.target in web browsers`

Can someone explain why Mozilla and Chrome have different values for e.target? I've created an example to demonstrate. Check out the example here In Mozilla, e.target displays as: <button type="button"> Whereas in Chrome, it shows as: < ...

using css styles in an angular component of a web application

I am currently developing an Angular 2 application with ASP.NET WebAPI 2 to retrieve data. Instead of using ASP.NET cshtml pages, I am utilizing HTML pages to display the content. Within my application project, I have two CSS files - Bootstrap.css and Site ...

Blurry text in Webkit browser after applying css transform (translate)

Having an issue with webkit transform. If I don't use -webkit-backface-visibility:hidden ... I notice flickering on many objects when I translate (e.g. -webkit-transform: translate(80%,0)) an object and If I do use -webkit-backface-visibility:hi ...

Having no capability to manipulate CSS using jquery

In one of my divs, the CSS is set to have display: none .cookie_policy { color: white; text-align: justify; width: 50%; margin: 2% 25%; line-height: 20px; display: block; font-family: Arial,Helvetica,sans-serif; font-style: italic; display:none; } <div ...

Is it possible to transfer my Bubble webpage to another hosting server?

Can I export the "Code" from bubble.io to create my own server? Appreciate any help! ...

Adjust the vertical alignment of spans within a div while ensuring that their height remains dynamic

Having a bit of trouble with my CSS. I have a single div with 3 columns inside: a span, an h3, and another span. Here's what I'm aiming for: - The div should adjust its height based on the content within the h3 tag ...

Make sure to utilize the className attribute when styling a Material-UI component

I am attempting to apply CSS styles to a Material-UI component. defined in MyCss.css .trackTitle { color:white; } located in myComponent.js import "./MyCss.css" <Grid container item xs={1} className="trackTitle"> change col ...

The background image is not appearing on the div as expected

I've been attempting to create a div and set a background image for it using jQuery, but I seem to be facing issues. When I try setting the background color to white, it works fine. Here's the code snippet: function appendToDom(poster) { ...

Is it possible to find a program that can extract information from a Hotmail webpage, such as the number of unread messages?

Does anyone know of a script that can be used to extract simple data from the hotmail/live mail web page? It doesn't matter what programming language it's in, but it would be best if it can run on Linux. This is because hotmail doesn't offer ...

Troubleshooting Problems with Owl Carousel Loading

Having trouble with Owl Carousel loading issue. I've set up my carousel using the Owl Carousel jQuery plugin as guided, but it's showing me an "owl-carousel loading" class added to the DOM (owl-loading). I've tried adding custom styles and J ...

Arrangement of multiple boxes in a single row using HTML code

Struggling to solve this supposedly simple problem, I'm reaching out for help. I need assistance in arranging multiple inputs with corresponding labels, all stacked horizontally on a single line as shown in the image. ...

Numerous translateX Functions in JavaScript (Webkit)

Trying to apply a .style.webkitTransform = 'translateX(10px)'; on an element and then adding another .style.webkitTransform = 'translateX(10px)'; to achieve a total of 20px is not feasible. The element will still remain at 10px. Is the ...

Table Header Stays Put Without Shrinking or Expanding with Window Adjustment

I have a sticky table header that stays at the top when scrolling down on my web page. To achieve this effect, I followed the solution provided on css-tricks.com/persistent-headers/. However, I encountered an issue where the sticky table header does not ...

Unable to retrieve HTML element using Python's Selenium

Whenever I try to access a specific website using Selenium, a pesky pop-up appears and I can't seem to locate the close button to dismiss it. from selenium import webdriver from time import sleep from selenium.webdriver.common.keys import Keys import ...

What is the best method to display and conceal a table row in Angular 6?

In the midst of developing a table with multiple rows, I am seeking a way to invisibilize a particular row and then reveal it again using a reset button. Any tips on how to accomplish this task?emphasis added ...

What is the best way to identify the specific button that has been clicked among a group of identical buttons in the given code snippet?

I am currently working on integrating a voting system for comments that allows users to upvote or downvote. To achieve this, I have added two buttons to each comment. With the help of jQuery's each() and click() functions, I am aiming to identify the ...