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



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

我可以让流体柱正确地生长和收缩,这样它就占据了容器中的剩余空间,将最大宽度设置为900px,但我无法让它获得最小宽度。

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

对th和/或td应用最小宽度不会有任何作用。对流体td内的div应用最小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>

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;
}

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

演示

.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;
}

我正在努力解决你的问题。在这种情况下,您的fluid没有最小宽度,因为这是表结构。但你可以给宽度。

请参阅此示例

.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;
	overflow: hidden;
    text-overflow: ellipsis;
}
td.fluid {
    background-color: #aaa;
    min-width: 100px;
    white-space: nowrap;
    overflow: hidden;
}
td {
    background-color: #ddd;
    border-right: 1px solid #333;
}
 tr td {
     text-align: center;
}
 }
table th, table td {
    border-top: 1px solid #333;
}
<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>

最新更新