固定宽度表中流体列的最小宽度

Pro*_*ist 5 html css html-table fixed-width

我正在尝试创建一个表格,其中流体列具有最小宽度。所有其他列都有固定的宽度,并且不应变宽或变薄。

我可以让流体柱正确地增长和收缩,以便它占据容器中的剩余空间,将最大宽度设置为 900px,但是我无法让它采用最小宽度。

这意味着当窗户和容器被压扁时,流体柱会被覆盖,而不是像此时的固定柱一样。

对 th 和/或 td 应用最小宽度不会执行任何操作。对流体 td 内的 div 应用 min-wdith 确实意味着文本具有最小宽度,但是它不会阻止列缩小到小于此最小值,因此文本位于下一列文本的下方。

有任何想法吗?

HTML:

<div class="container">
<table>
    <thead>
        <tr>
            <th class="fixed">fixed</th>
            <th class="fixed">fixed</th>
            <th class="fixed">fixed</th>
            <th class="fluid">fluid</th>
            <th class="fixed">fixed</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>fixed</td>
            <td>fixed</td>
            <td>fixed</td>
            <td class="fluid"><div align="left">Some text here which gets truncated, however should have min width</div></td>
            <td>fixed</td>
        </tr>  
    </tbody>            
</table>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.container {
    max-width: 900px;
}

table {
    table-layout: fixed;
    width: 100%;
    border: 1px solid #333;
    border-collapse: separate;
    border-spacing: 0;
}

th.fixed {
    width: 100px;
}

th.fluid {
    min-width: 100px;
}

td.fluid div {
    width: auto;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
}

td.fluid {
    background-color: #aaa;
    min-width: 100px;
}

td {
    background-color: #ddd;
    border-right: 1px solid #333;
}

tr td {
     text-align: center;
}

table th, table td {
    border-top: 1px solid #333;
}
Run Code Online (Sandbox Code Playgroud)

JSfiddle: http: //jsfiddle.net/ajcfrz1g/14/

小智 1

演示版

.container {
    max-width: 900px;
}

table {
    table-layout: fixed;
    width: 100%;
     min-width: 500px;
    border: 1px solid #333;
    border-collapse: separate;
    border-spacing: 0;
}


th.fixed {
    width: 100px;


}

th.fluid {
    min-width: 100px;
}

td.fluid div {
    width: 100%;
    min-width:100px;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
}

td.fluid {
    background-color: #aaa;
    min-width: 100px;
    width: 100%;
}

td {
    background-color: #ddd;
    border-right: 1px solid #333;
}
 tr td {
     text-align: center;
}
 }

table th, table td {
    border-top: 1px solid #333;
}
Run Code Online (Sandbox Code Playgroud)