Td Background: Here's The CSS To Replace The HTML Code With
- Attribute of
- Dealing With Td Layout Issues In HTML5 - Quick Tutorial
- What does
Td Background: Here's The CSS To Replace The HTML Code With
do? - Specifies the URL of an image file to be used as the <td> element background image.
Code Example
<table>
<tr>
<td>This cell has no background attribute.</td>
<td background="/wp-content/uploads/blue.edge_.gif">This cell has a background attribute.</td>
</tr>
</table>
This cell has no background attribute. | This cell has a background attribute. |
The Background Attribute has been Deprecated
At one time, before the use of CSS was prevalent with broad browser support, styling was added directly to HTML documents through the use of attributes like background
. However, that’s no longer the case. Use of background
as an attribute for the td
element has been deprecated. If you want to apply a background image to a table’s cells you can do so with the CSS background property.
How background
Works
The background
property was used to provide the URL of an image that would be applied as a background image to a td
element. The property could only be used to specify the URL of an image. If you wanted to apply a color instead of an image you would have to use the bgcolor
attribute. However, both of these attributes have been deprecated in favor of the CSS background property and should not be used any longer. While they may still work in some browsers, they will not pass HTML validation and browsers may drop support for these attributes at any time. To use CSS to apply a background image, do something like this:
<style> .bluecolor { background: blue; } .blueimage { background-image: url("/wp-content/uploads/blue.edge_.gif"); } </style> <table> <tr> <td class="bluecolor">This cell has no background attribute.</td> <td class="blueimage">This cell has a background attribute.</td> </tr> </table>
Here’s how those CSS properties are applied to the table data cells.
This cell has no background attribute. | This cell has a background attribute. |