Html 表指定以 px 为单位的列宽不起作用
我正在尝试制作一个 ajax 列可调整大小的表格,界面工作正常,但是当我调整列大小时,浏览器会以最大 100% 放大表格,最终调整其他列的大小。 我已经尝试过这两种解决方案,但没有一种效果很好:
1.
min-width: 100%;
table-layout: fixed;
width: 100%;
使用此解决方案,我需要在(如有必要)超过 100% 之前调整任何单个列的大小;例如,如果我只放大一列,则所有其他列都受到限制,它们不会保持原始宽度(就像我一样)
2.
table-layout: fixed;
有什么想法吗?
编辑: 这是相关的 html 代码:
<table class="resizable" id="TabellaDati" ><thead> <tr>
<th id="MDT_ThID"><span>ID</span></th>
<th id="MDT_ThText" style="width: 146px;">Text</th>
<th id="MDT_ThTitle" style="width: 148px;">Title</th>
<th id="MDT_ThCssClass" style="width: 83px;">CssClass</th>
<th id="MDT_ThUrl" style="width: 92px;">Url</th>
<th id="MDT_ThOrdine">Ordine</th>
</tr>
</thead>
<tbody> <tr>
<td headers="MDT_ThID">MenuAlbo</td>
<td headers="MDT_ThText">Albo Pretorio</td>
<td headers="MDT_ThTitle">Albo Pretorio</td>
<td headers="MDT_ThCssClass"></td>
<td headers="MDT_ThUrl">/AlboPretorio</td>
<td headers="MDT_ThOrdine">2</td>
</tr>
</tbody></table>
和 Css:
#TabellaDati {
min-width: 100%;
table-layout: fixed;
width: 100%;
}
table {
border-collapse: collapse;
}
I'm trying to make an ajax columns-resizable table, the interface works fine, but when I resize the columnns, the browser enlarges the table at max 100%, resizing eventually other columns.
I've tried with both this two solutions but no one works well:
1.
min-width: 100%;
table-layout: fixed;
width: 100%;
with this solution, I need to resize any single column before going (if necessary) over 100%; if I enlarge only one column, for example, all the others columns are restricted, they does not maintain the original width (as I would)
2.
table-layout: fixed;
Any ideas?
Edit:
This is the relevant html code:
<table class="resizable" id="TabellaDati" ><thead> <tr>
<th id="MDT_ThID"><span>ID</span></th>
<th id="MDT_ThText" style="width: 146px;">Text</th>
<th id="MDT_ThTitle" style="width: 148px;">Title</th>
<th id="MDT_ThCssClass" style="width: 83px;">CssClass</th>
<th id="MDT_ThUrl" style="width: 92px;">Url</th>
<th id="MDT_ThOrdine">Ordine</th>
</tr>
</thead>
<tbody> <tr>
<td headers="MDT_ThID">MenuAlbo</td>
<td headers="MDT_ThText">Albo Pretorio</td>
<td headers="MDT_ThTitle">Albo Pretorio</td>
<td headers="MDT_ThCssClass"></td>
<td headers="MDT_ThUrl">/AlboPretorio</td>
<td headers="MDT_ThOrdine">2</td>
</tr>
</tbody></table>
And the Css:
#TabellaDati {
min-width: 100%;
table-layout: fixed;
width: 100%;
}
table {
border-collapse: collapse;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几天前我回答了一个关于用css设置列宽的问题。首先确保设置正确可能会有所帮助。如何设置表格列宽.. 基本上我发现我需要设置表格宽度以及 th/td。之后,表格布局:固定应该可以正常工作。
编辑:
所以,我错过了您将单元格宽度设置为内联。所以我加载了你的标记和 CSS,看起来很棒。 (我正在使用 Chrome)
然后我很困惑问题是什么,所以我也意识到这很可能是 AJAX 问题。我对 AJAX 不太热衷,但我仍在检查它。
更新:
您有必须使用 Ajax 的理由吗?也就是说,通过使用 AJAX 而不是像这样的普通 Javascript,您可以获得什么好处:
我觉得这会变得更容易,并且它与您拥有的标记和样式保持良好的格式。
如果您坚持使用 AJAX,请提供您关于 AJAX 的代码。
I answered a question on setting column width with css a couple of days ago. It may help to make sure that is set up correctly first.How to set table column width.. Basically I found I needed to set the table width as well as the th/td. After that the table-layout: fixed should work alright.
EDIT:
SO, I missed that you had the cell width set inline. So I loaded your markup and css and that looks great. (I'm using Chrome)
Then I was confused what the issue was and so I also realized that this is most likely an AJAX issue. I'm not so hot with AJAX, but I'm still checking it out.
UPDATE:
Is there a reason why you must use Ajax? That is, what benefit are you gaining by using AJAX instead of plain ol' Javascript like this:
I feel like this would be a whole world easier, and it stays well formatted with the markup and styling you have.
If you are adamant in using AJAX, please provide what your code regarding AJAX.