tags:

views:

3344

answers:

5

VStudio ASP.NET gives the following message:

Attribute 'bgcolor' is considered outdated. A newer construct is recommended.

What is the recommended construct?

bgcolor is within a <td> element.
Another related message is :

Attribute 'bordercolor' is not a valid attribute of element 'table'.

Does anyone know where I might find the newer replacements?

+2  A: 

The newer replacement is cascading style sheets (CSS). Any attributes or elements that control the visual appearance of an HTML document are deprecated. Visual styles should be specified using CSS.

Tmdean
+4  A: 

Best guess would be CSS's background-color and border-color:

<table style="border-color: #ffffff;">

<td style="background-color: #000000;">
Jonathan Lonowski
Thanks Jonathan. This answers my immediate question perfectly. The CSS path though is what I should be heading down in the long term.
Anthony K
Yea, it's something that will make your life much easier once you do it.
George Stocker
+13  A: 

BGColor was deprecated in the W3C HTML 4.0 Specification.

Newer Web sites and web applications use CSS (Cascading Style Sheets) to render the same thing, as follows:

   body {
  background-color : #ffffff;
}

For tables, do the following:

<table>

<tr id="row1">
   <th>Header 1</th>      <td>Cell 1</td>        <td>Cell 2</td>
</tr>
<tr id="row2">
   <th>Header 2</th>      <td>Cell 3</td>        <td>Cell 4</td>
</tr>
<tr id="row3">
   <th>Header 3</th>      <td>Cell 5</td>        <td>Cell 6</td>
</tr>
</table>

And in your CSS:

th { text-align: center; font-weight: bold; vertical-align: baseline }

td { vertical-align: middle  }

table  { border-collapse: collapse; background-color: #ffffff }
tr#row1 { border-top: 3px solid blue }
tr#row2 { border-top: 1px solid black }
tr#row3 { border-top: 1px solid black }

That will make it so the table will have a background color, and do different stuff with the rest of the table data/table rows.

Simply put that in your style sheet and reference it on your web page like so:

<link rel="stylesheet" href="style.css" TYPE="text/css" media="screen">

You can put just about whatever you like in your CSS, more information on CSS here, and here.

George Stocker
I also found a good reference for deprecated HTML elements:http://www.doheth.co.uk/codelair/html-css/deprecated
Anthony K
+2  A: 

The recommended way to do things like this is to use CSS. You could set up CSS classes for your table. Something like this:

CSS:

.MyTable {
    border: solid 2px #000;
}

.MySpecialCell {
    background-color: #F00;
}

HTML:

<table class="MyTable">
    <tr>
        <td class="MySpecialCell">...</td>
    </tr>
</table>
Jeromy Irvine
+1  A: 

It's also worth noting, that while not as elegant as a seperate style section, it is valid now to do it this way, with inline styles, if this is what you're more comfortable with:

<body style="background-color: #ccc;">
danieltalsky