不赞成使用HTML属性bgcolor:用什么代替?

时间:2022-11-12 11:20:29

VStudio ASP.NET gives the following message:

VStudio ASP。NET提供了以下信息:

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 :

bgcolor在元素内。另一个相关信息是:

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

Does anyone know where I might find the newer replacements?

有人知道我在哪里可以找到新的替代品吗?

5 个解决方案

#1


20  

BGColor was deprecated in the W3C HTML 4.0 Specification.

在W3C HTML 4.0规范中,BGColor被弃用。

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

更新的Web站点和Web应用程序使用CSS(级联样式表)呈现相同的内容,如下所示:

   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:

和你的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.

你可以把你喜欢的东西放在你的CSS里,更多关于CSS的信息,这里。

#2


4  

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

最好的猜测是CSS的背景色和边框色:

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

<td style="background-color: #000000;">

#3


3  

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:

同样值得注意的是,虽然不如seperate风格部分那么优雅,但现在这样做是有效的,使用内联样式,如果这是您更舒服的方式:

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

#4


2  

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.

更新的替代是层叠样式表(CSS)。任何控制HTML文档外观的属性或元素都不被使用。应该使用CSS指定视觉样式。

#5


2  

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。您可以为您的表设置CSS类。是这样的:

CSS:

CSS:

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

.MySpecialCell {
    background-color: #F00;
}

HTML:

HTML:

<table class="MyTable">
    <tr>
        <td class="MySpecialCell">...</td>
    </tr>
</table>

#1


20  

BGColor was deprecated in the W3C HTML 4.0 Specification.

在W3C HTML 4.0规范中,BGColor被弃用。

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

更新的Web站点和Web应用程序使用CSS(级联样式表)呈现相同的内容,如下所示:

   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:

和你的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.

你可以把你喜欢的东西放在你的CSS里,更多关于CSS的信息,这里。

#2


4  

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

最好的猜测是CSS的背景色和边框色:

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

<td style="background-color: #000000;">

#3


3  

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:

同样值得注意的是,虽然不如seperate风格部分那么优雅,但现在这样做是有效的,使用内联样式,如果这是您更舒服的方式:

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

#4


2  

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.

更新的替代是层叠样式表(CSS)。任何控制HTML文档外观的属性或元素都不被使用。应该使用CSS指定视觉样式。

#5


2  

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。您可以为您的表设置CSS类。是这样的:

CSS:

CSS:

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

.MySpecialCell {
    background-color: #F00;
}

HTML:

HTML:

<table class="MyTable">
    <tr>
        <td class="MySpecialCell">...</td>
    </tr>
</table>