首頁  >  文章  >  web前端  >  如何在HTML中顯示元素的背景顏色?

如何在HTML中顯示元素的背景顏色?

WBOY
WBOY轉載
2023-08-27 19:57:19711瀏覽

如何在HTML中顯示元素的背景顏色?

使用 HTML 中的bgcolor屬性來顯示元素的背景顏色。它用於控制 HTML 元素的背景,特別是頁面正文和表格背景。

注意 - HTML5 不支援此屬性。

範例

您可以嘗試執行以下程式碼來了解如何在 HTML 中實作 bgcolor 屬性 -

<!DOCTYPE html>
<html>
   <head>
      <title>HTML Background Colors</title>
   </head>
   <body>
      <!-- Format 1 - Use color name -->
      <table bgcolor = "yellow" width = "100%">
         <tr>
            <td>
               This background is yellow
            </td>
         </tr>
      </table>

      <!-- Format 2 - Use hex value -->
      <table bgcolor = "#6666FF" width = "100%">
         <tr>
            <td>
               This background is sky blue
            </td>
         </tr>
      </table>

      <!-- Format 3 - Use color value in RGB terms -->
      <table bgcolor = "rgb(255,0,255)" width = "100%">
         <tr>
            <td>
               This background is green
            </td>
         </tr>
      </table>
   </body>
</html>

以上是如何在HTML中顯示元素的背景顏色?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除