Jul*_*ien 43 html css html-table autosize
我在div中有一个to-columns表:
<div>
<table>
<tbody>
<tr>
<td class="action" >
<a> ? </a>
</td>
<td class="content">
<p>Bigger text...(variable size).......</p>
</td>
</tr>
<tr>
<td class="action" >
<a> ? </a><a> ? </a>
</td>
<td class="content">
<p>Bigger text...(variable size).......</p>
</td>
</tr>
... same structure in all the table
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望"action"列适合内容,而"content"列则需要剩余的可用空间.使用右对齐,"action"列看起来会更好.桌子也应该适合容器宽度的100%.
有没有办法在不修复列宽的情况下这样做?
我试过这个:
table .action
{
width:auto;
text-align:right;
}
table
{
border-collapse:collapse;
border-spacing:0;
width:100%;
}
Run Code Online (Sandbox Code Playgroud)
但左栏占据了一半的表......
Ste*_*ler 36
给内容td100%的宽度将迫使它占用尽可能多的空间,所以.content{ width: 100% }应该工作.
同时给出.action a white-space: nowrap以确保x和复选标记保持彼此相邻.否则,内容将能够占用更多空间并将图标强制在彼此之下.
table .action
{
width:auto;
text-align:right;
white-space: nowrap
}
table .content {
width: 100%
}
table
{
border-collapse:collapse;
border-spacing:0;
width:100%;
border: 1px solid
}Run Code Online (Sandbox Code Playgroud)
<table>
<tbody>
<tr>
<td class="action" >
<a> ? </a>
</td>
<td class="content">
<p>Bigger text...(variable size).......</p>
</td>
</tr>
<tr>
<td class="action" >
<a> ? </a><a> ? </a>
</td>
<td class="content">
<p>Bigger text...(variable size).......</p>
</td>
</tr>
</tbody>
</table>Run Code Online (Sandbox Code Playgroud)
Kir*_* Jr 18
设置列width: 1px和white-space: nowrap.
这将尝试使其为1px,但nowrap将阻止它变得小于该列中最宽的元素.