html - 如何固定表格中的 td 宽度

标签 html css

我在我的元素中使用 easyui-panel 和一张表。

我想固定每个td width:50px;

这是我的代码:

<div  class="easyui-panel" id="pp"  style="margin-top:30px;width:100%">
        <table class="uTbId"  cellspacing="0" style="width:100%" >
         <tr>
           <td style="position:absolute;width:50px;background-color:#fafafa">stack</td>
           <td style="position:absolute;width:50px;background-color:#fafafa">john</td>
           <td style="position:absolute;width:50px;background-color:#fafafa">stock</td>
           <td style="position:absolute;width:50px;background-color:#fafafa">shansa</td>
         </tr>
         <tr>
           <td style="postion:absolute;width:50px;background-color:#fafafa">Joy</td>
         </tr>
        </table>
</div>

但它工作失败。堆栈、约翰和股票都消失了。我的 table 状态不正常。

当我删除“position:absolute;width:50px;”后,所有的名字都可以显示。like:

<div  class="easyui-panel" id="pp"  style="margin-top:30px;width:100%">
    <table class="uTbId"  cellspacing="0" style="width:100%" >
     <tr>
       <td style="background-color:#fafafa">stack</td>
       <td style="background-color:#fafafa">john</td>
       <td style="background-color:#fafafa">stock</td>
       <td style="background-color:#fafafa">shansa</td>
     </tr>
     <tr>
       <td style="background-color:#fafafa">Joy</td>
     </tr>
    </table>
 </div>

所有的名字都可以不固定宽度出现,但这不是我想要的。

谁能帮帮我?

最佳答案

您不需要同时删除 position:absolutewidth:50px .

删除 position:absolutewidth:100%来自 <table>应该会产生你想要的结果。所以现在你的 HTML 看起来像

<div  class="easyui-panel" id="pp"  style="margin-top:30px;width:100%">
    <table class="uTbId"  cellspacing="0">
     <tr>
       <td style="width:50px;background-color:#fafafa">stack</td>
       <td style="width:50px;background-color:#fafafa">john</td>
       <td style="width:50px;background-color:#fafafa">stock</td>
       <td style="width:50px;background-color:#fafafa">shansa</td>
     </tr>
     <tr>
       <td style="width:50px;background-color:#fafafa">Joy</td>
     </tr>
    </table>

如果结果不是您想要的,可能是某些 CSS 样式向 <td> 添加了额外的填充或边距。元素。启动开发人员控制台(在大多数浏览器上为 F12)-> 右键单击​​您的元素 -> 检查并在 CSS 样式部分查看盒模型以了解是否应用了任何额外的填充/边距

关于html - 如何固定表格中的 td 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48333254/

相关文章:

javascript - 是否可以输入 ="text"以要求电子邮件或电话?

html - CodeIgniter CSS 不会链接到 html

html - 如何将边界半径应用于带填充的图像?

css - 当我最小化页面时,网格中的网格移动

html - 2个div之间的空白?

python - 如何在python中的html电子邮件中添加python代码?

html - 为什么属性 "disabled"而不是 "enabled"

javascript - 如何更改转换 :translate css rule according to the screen resolution?

css - 需要在文本区域的占位符上添加一些 padding-top

jquery - 如何更改特定菜单项的文本颜色?背景改变但文字颜色不变?