- 0133技术站
- 联系QQ:88526
- QQ交流群
- 微信公众号
定义
bgcolor属性规定表格的背景颜色。
语法
<table bgcolor="color_name|hex_number|rgb_number">
属性值
● color_name:规定颜色值为颜色名称的背景颜色(比如 "red")。
● hex_number:规定颜色值为十六进制值的背景颜色(比如 "#ff0000")。
● rgb_number:规定颜色值为 rgb 代码的背景颜色(比如 "rgb(255,0,0)")。
兼容性注释
在 HTML 4.01 中,<table> 的 bgcolor 属性 已废弃。HTML5 不支持 <table> bgcolor 属性。请使用 CSS 代替。
CSS 语法:<table style="background-color:red">
在我们的 CSS 教程中,您可以找到更多有关 background-color 属性 的细节。
浏览器支持
属性 | |||||
bgcolor | 支持 | 支持 | 支持 | 支持 | 支持 |
所有主流浏览器都支持 bgcolor 属性。
带有背景颜色的 HTML 表格:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>0133技术站(0133.cn)</title> </head> <body> <table border="1" bgcolor="#00FF00"> <tr> <th>商品</th> <th>价格</th> </tr> <tr> <td>T恤</td> <td>¥50.00</td> </tr> <tr> <td>夹克衫</td> <td>¥80.00</td> </tr> </table> <p><b>提示:</b>如果所有浏览器要显示相同颜色,要使用十六进制的颜色代码。</p> <p><b>注意:</b>在HTML 4中 bgcolor 属性已废弃,HTML5 已不支持该属性,可以使用 CSS 代替。</p> </body> </html>
点击 "运行实例" 按钮查看在线实例
CSS 实例:表格背景颜色
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>0133技术站(0133.cn)</title> </head> <body> <table border="1" style="background-color:#00FF00"> <tr> <th>商品</th> <th>价格</th> </tr> <tr> <td>T恤</td> <td>¥50.00</td> </tr> <tr> <td>夹克衫</td> <td>¥80.00</td> </tr> </table> </body> </html>
点击 "运行实例" 按钮查看在线实例
推荐手册