html表格怎么添加背景图(html中新建表格怎么加背景颜色填充)

lxf2023-03-08 17:30:01

在html中,可以使用background属性设置新建表格中的背景,只需要给表格元素设置“background:属性值”即可。background属性在一个声明中设置所有的背景属性,可以设置对象为纯色的背景颜色,也可以设置图片为背景。

html表格怎么添加背景图(html中新建表格怎么加背景颜色填充)

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

表格的颜色设置非常简单,和文字的颜色设置完全一样。

CSS通过background属性设置表格的背景;通过color属性设置表格中文字的颜色。

示例:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        background-color: #ebf5ff;
        margin: 0px;
        padding: 4px;
        text-align: center;
      }
      table {
        background: pink;
        color: white;
      }
    </style>
  </head>

  <body>
    <table border="1">
      <tr>
        <th>NAME</th>
        <th>AGE</th>
        <th>NUMBER</th>
      </tr>
      <tr>
        <td rowspan="2">xm</td>
        <td>10</td>
        <td>2020</td>
      </tr>
      <tr>
        <td>3</td>
        <td>2021</td>
      </tr>
      <tr>
        <td>xf</td>
        <td>4</td>
        <td>2010</td>
      </tr>
    </table>
  </body>
</html>

效果:

html表格怎么添加背景图(html中新建表格怎么加背景颜色填充)

推荐学习:html视频教程

以上就是HTML中新建表格怎么加背景的详细内容,更多请关注AdminJS其它相关文章!