【问题标题】:How can display table-row behave like colspan=3显示表格行如何表现得像 colspan=3
【发布时间】:2016-07-24 17:41:00
【问题描述】:

我需要两行,第一行有 3 列,第二行我需要像 td colspan=3 那样跨越所有宽度

或者显示:table-cell;表现得像 colspan=3

我正在使用display: table-row; width: 100%;

怎么做?

这是我的 CSS:

<style>
      .boxer {
         display: table;
         border-collapse: collapse;
      }
      .boxer .box-row {
         display: table-row;
      }
      .boxer .box-row-search {
         display: table-row;
         width: 100%;
      }
      .boxer .box {
         display: table-cell;
         text-align: left;
         vertical-align: top;
         border: 1px solid black;
      }
</style>

【问题讨论】:

  • 最好也发布 HTML。
  • 这是 HTML:`
    2
    3
    4
    `

标签: css


【解决方案1】:

使用display: table;it cannot be done(遗憾的是CSS中没有colspan: 3;rowspan属性,因此样式表无法模仿真实的&lt;table&gt;元素)

但是,嘿,flex 来救援!

.row{
  display: flex;
  flex-flow: wrap;
}
.cell{
  width: 25%;
  background:#eee;
}
.colspan2{
  flex: 2;
}
<div class="row">
  <div class="cell">Cell1</div>
  <div class="cell">Cell2</div>
  <div class="cell">Cell3</div>
  <div class="cell">Cell4</div>
  <div class="cell">Cell5</div>
  <div class="cell colspan2">Cell6 Colspan2</div>
  <div class="cell">Cell7</div>
</div>

【讨论】:

  • 非常感谢 Roko,它对我帮助很大。我现在只是在寻找 CSS 响应式
  • 酷! @ÂngeloRigo,不客气!它完全响应 jsbin.com/heriyo/1 所以去吧。
  • 我可以试试 2 行吗,第一行有 3 列,3 列 rowspan = 2,第二行 colspan=2
猜你喜欢
  • 1970-01-01
  • 2021-04-19
  • 2013-04-14
  • 2014-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-17
相关资源
最近更新 更多