Home >Web Front-end >CSS Tutorial >How to set the width of table to adaptive width in css

How to set the width of table to adaptive width in css

WBOY
WBOYOriginal
2021-12-08 14:54:4512271browse

在css中,可以利用width属性设置table元素的宽度为自适应宽度,该属性用于设置元素的宽度,当属性的值为“数值%”时,定义基于包含父元素宽度的百分比宽度,也即宽度随父元素宽度自适应,语法为“table{width:数值%;}”。

How to set the width of table to adaptive width in css

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

css怎样设置table的宽度为自适应宽度

在css中,利用width属性,该属性用于设置元素的宽度,将属性的值设置为百分比样式可以将元素的宽度设置为自适应宽度。

示例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    table{
        width:50%;
    }
    </style>
</head>
<body>
<table border="1">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>
</body>
</html>

输出结果:

How to set the width of table to adaptive width in css

(学习视频分享:css视频教程

The above is the detailed content of How to set the width of table to adaptive width in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn