html - CSS 表格单元格不会变成全宽

标签 html css css-tables

我想用纯 CSS 创建一个表格设计。我给 <span> 上了不同的课标签。它们定义单元格的宽度。现在我想插入一行单列(宽度 100%)。但是 <span>标签不会变成 100%。

请看例子:

<div class="table">
    <span class="row head">
        <span class="cell w40">
            Title
        </span>
        <span class="cell w20">
            Title
        </span>
        <span class="cell w20">
            Title
        </span>
        <span class="cell w20">
            Title
        </span>
    </span>
    <span class="row single"><span class="cell center">Full width?</span></span>
</div>

CSS:

.table {
  display: table;
  width: 100%;
  max-width: 800px;
}
.table .row {
  display: table-row;
  width: 100%;
}
.table .row.head {
  font-weight: 600;
  background: #d4291f;
  color: white;
}
.table .row.head:hover .cell {
  background: #d4291f;
}
.table .row:hover .cell {
  background: #eeeeee;
}
.table .row.single .cell {
  width: 100%;
  display: block;
}
.table .cell {
  padding: 8px 8px;
  vertical-align: top;
  display: table-cell;
}
.table .cell.w40 {
  width: 40%;
}
.table .cell.w20 {
  width: 20%;
}
.table .cell.center {
  text-align: center;
}

你有什么想法吗?

最佳答案

经过一些研究,我相信这是让它发挥作用的方法。 Demo Link

<div class="table">
<span class="row head">
    <span class="cell w40">
        Title
    </span>
    <span class="cell w20">
        Title
    </span>
    <span class="cell w20">
        Title
    </span>
    <span class="cell w20">
        Title
    </span>
</span>
</div>
<div class="table">
  <span class="row single">
    <span class="cell center">
      Full width?
    </span>
  </span>
</div>

.css 只改变了一点,我删除了“width: 100%;”

.table .row.single .cell {
  display: block;
}

关于html - CSS 表格单元格不会变成全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24843773/

相关文章:

Javascript/Jquery委托(delegate)点击触发视频功能两次

html - 悬停在 slider 内的按钮上不起作用

html - 如何定位表格单元格 (td) 中的元素,使一个元素左对齐而另一个元素右对齐?

html - 表类在 css/html 中不起作用

javascript - 使用 JS 在可变大小的 div 中缩放和居中图像

css - YII2 前端的自定义 Bootstrap css

css - 在 IE 11 中使用最大宽度和最大高度保持图像比例

html - 防止 H1 标签换行

html - 表断章取义

javascript - 显示多个图像 - javascript