html - 表格调整 th 和 td 的行宽

标签 html css

我有一张 table 和 <th><td>假设宽度相同,我在 sass 和 css 中做错了什么? nth-child(1)nth-child(2)假设有 20% 和 nth-child(3) 60%,我做错了什么?谢谢。

sass 代码:

 table {
      th,td:nth-child(1),
      th,td:nth-child(2) {
        width: 20%;
      }
      th,td:nth-child(3) {
        width: 60%;
      }

      tr {
        width: 100%;
        table-layout: fixed;
        display: inline-table;
      }
  }

table th, table td:nth-child(1),
table th, table td:nth-child(2) {
  width: 20%;
}
table th, table td:nth-child(3) {
  width: 60%;
}
<table>
  <thead>
    <th>1</th>
    <th>2</th>
    <th>3</th>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>3</td>
    </tr>
  </tbody>
</table>

最佳答案

这是一个简单的解决方案:

将表格宽度设置为 100%

table {
  width: 100%;
  text-align: center;
}

th {
  width: 20%;
}

th:nth-child(3) {
  width: 60%;
}

就这些

关于html - 表格调整 th 和 td 的行宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45816643/

相关文章:

jquery - 搜索弹出图标 : Like Apple. com Angular JS

html - 如何使用自定义字体图标?

javascript - 如果当前日期 > 今天不工作 Javascript

javascript - 表格的 CSS 或 JavaScript (JQuery) Stickyheader

jquery - 如何与 Fancybox3 字幕 block 中的表单输入进行交互?

php - 以 HTML 形式将文件存储在 MySQL 数据库中

html - 粘性页脚在横向方向中断

javascript - Android上的HTML5音频自动播放-iframe技巧

html - iPhone 试图将所有内容压缩到一页上

javascript - 如何增加外支架的高度?