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

更新於: 02-Mar-2020

836 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.