Table cell padding woes with Chrome

时光毁灭记忆、已成空白 提交于 2019-12-11 05:42:52

问题


I am having a lot of trouble with table cell paddings in Chrome. It seems that if a table cell does not contain pure text, then no padding is applied at all.

My markup:

<table>
        <tr>
            <th></th>
            <th class="account-picture"></th>
            <th class="account-name">Name</th>
            <th class="account-email">Email</th>
            <th class="account-last">Last Sign in</th>
        </tr>

        <tr>
            <td>
                <fieldset>
                   <ul>        
                       <li><input type="checkbox" id="enabled" name="test[]" value="enabled"></li>
                   </ul>    
                </fieldset>
            </td>

            <td class="account-picture">
                   <div class="online">
                      <img src="http://www.genengnews.com/app_themes/genconnect/images/default_profile.jpg">                           </div>
            </td>
            <td class="account-name">test test test test test test test test test test test test test test test test test test</td>
            <td class="account-email">test test test test test test test test test test test test test test test test test test</td>
            <td class="account-last">15 April 2012 10:19 AM</td>
        </tr>
</table>

The CSS:

img{ 
    height: 42px;
    width: 42px;
}

td, th{      
    padding: 0 12px;
    vertical-align: middle;
}

.account-picture{
    width: 40px;

}

.account-name{
    min-width: 100px;
}

.account-email{
    min-width: 120px;
}

.account-last{
    min-width: 140px;
}

table{
    table-layout: fixed;
    float: none;
    width: 100%;
    margin-top: 10px;
 }

td, th{      
   word-wrap: break-word;
   padding: 0 12px;
   vertical-align: middle;
}

td:first-child, th:first-child{
  width: 14px;
}

And the fiddle: http://jsfiddle.net/5mPFk/1/

And this is what it renders as in firefox 11:

Chrome: 18 (latest):

IE9:

As can be seen, IE and FF works properly, but not with chrome. Why is this happening and what are possible solutiosn for this?


回答1:


Removed table-layout: fixed and it seems to work.

If table-layout: fixed is to be used, then width instead of min-width should be use to define column widths.

Not sure why only Chrome was playing up, but perhaps it has a better standards implementation.



来源:https://stackoverflow.com/questions/10158893/table-cell-padding-woes-with-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!