【问题标题】:div (table-cell) does not expand when width is set to 100%当宽度设置为 100% 时,div(表格单元格)不会扩展
【发布时间】:2018-11-04 18:44:53
【问题描述】:

我将表格元素转换为所有 div,但当 width 属性设置为 100% 时,元素的 div 不会像 colspan="5" 那样扩展。如何使它扩展全宽?如何扩展全宽第二行?

<style>
    .table {
        display: table;
        width: 100%;          
    }
    .tr {
        display: table-row;   
        width: 100%;         
    }
    .td {
        display: table-cell;
        width: 100%;
        padding: 10px;
        border: black solid 1px;
    }
</style>



<div class="table">
        <div class="tr">
            <div class="td">Product</div>
            <div class="td">Unit Price</div>
            <div class="td">Quanity</div>
            <div class="td">Total Points</div>
            <div class="td">Temp</div>
        </div>
        <div class="tr">
            <div class="td">
                <span>Serial Number</span>
                <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
                    <input maxlength="50" name="serialNo" id="serialNo" type="text">
                </div>
            </div>
        </div>
 </div>

【问题讨论】:

  • 这是表格数据,使用表格。
  • 他有自己的理由使用div
  • 正如 Alexdn 所说,我必须使用 div 而不是 table 元素。我想到了 Bootstrap 框架,gridview 响应式。也许,它可以解决这个问题。

标签: html css-tables


【解决方案1】:

使用表格布局:固定:

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

另外,我建议您在表格形式中使用&lt;table&gt; 而不是&lt;div&gt;

【讨论】:

  • 这会导致一行中的所有表格单元格的宽度相等 - 这看起来不像 OP 想要的(见图)
  • 不幸的是,问题是我必须使用 div 而不是 table 元素
猜你喜欢
  • 2013-05-27
  • 1970-01-01
  • 2014-07-09
  • 2011-03-03
  • 2023-01-13
  • 2012-11-15
  • 1970-01-01
  • 2017-12-24
  • 1970-01-01
相关资源
最近更新 更多