如何在 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>

更新於: 2020 年 3 月 2 日

836 次瀏覽

開啟您的 職業生涯

完成課程,獲取認證

開始
廣告