【问题标题】:Strange CSS positioning behavior奇怪的 CSS 定位行为
【发布时间】:2013-07-01 00:38:45
【问题描述】:

我完全无法理解为什么这个div 中的表格向右对齐得如此糟糕。

<div id="proof_check" style="position:relative; width:577px;  padding:10px; padding-bottom:0px;padding-top:0px; border:3px solid #ccc;  background-color:#fff; z-index:0"> 
<table><tr><td></td><td style='vertical-align:top; padding-left:5px;'><span style='font-weight:bold; color: #295BA7;'>Proof Approval</span><br /></td></tr><tr><td><input type='checkbox' id='proof-approved'></td><td style='vertical-align:top;padding-left:5px;'>I approve of the above design, spelling and layout and understand that my document will print as it appears above and that after placing my order, it cannot be changed.</td></tr><tr valign=bottom><td colspan='2'></td>
</tr>
</table>
</div>

结果是这样的:

到底为什么它从 div 的中间开始而不是从左侧开始?

【问题讨论】:

标签: html css html-table position alignment


【解决方案1】:

您没有为表格的“td”列提供任何 colspan 或宽度。因此,它将表格行 'tr' 分成两个相等的部分。

给一个 colspan 元素,如:

<TABLE STYLE="table-layout:fixed;">
  <COLSPAN>
   <COL width="5%"/>
   <COL width="95%">
  </COLSPAN>
  ....rest of the code goes here...
</TABLE>

每次第一列占 5%,第二列占 95% 宽度。

希望有帮助

【讨论】:

    【解决方案2】:

    代码似乎没问题,我能找出的唯一问题是您的 proof_check div 中的“position:relative”,也许是您的父 div 导致了问题。 将其更改为“位置:绝对” 希望能解决您的问题!

    【讨论】:

      【解决方案3】:

      这是因为您没有为第一个表格单元格定义宽度(带有复选框)。设置它的宽度,你应该没问题......或者用div而不是表格来做。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-09
        • 2019-01-06
        • 1970-01-01
        • 2010-09-16
        • 1970-01-01
        • 2018-03-04
        相关资源
        最近更新 更多