日期:2014-05-17  浏览次数:20577 次

table width 100% 后,TD不能靠左的问题
页面代码如下.

 <table cellspacing="0" cellpadding="3" border="0" width="100%" style="float:left;" >
  <tbody >
<tr style="height:23px;background: none repeat scroll 0 0 #E5ECF9; padding:2; float:left;">  
  <td style="float:left; width:50px;" align="left" >用户名:</td>
  <td style="float:left;width:130px;" align="left">
  <input type="text" value="" name="userids" id="userids" />
  </td>

  <td style="width:70px; " align="left"><input type="submit" style="width:60px; height:18px;" value="查询" id="search" class="button2" name="search" /></td>
  </tr>  
  </tbody>
</table>

table 宽度,100%后 TR 里面的三个TD ,全部居中了,我看效果是平分了,整个宽度.
请问怎么能让td全部靠左呢.



------解决方案--------------------
1. 表现要与结构分离。
2. 外边百分比,里边必用百分比。
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>test-csdn-table</title>
    <style type="text/css">
        .data_show{border-collapse:collapse; border:1px solid #ccc;}
        .data_show th{ background:#E5ECF9;}
        .data_show td{ background:#E5ECF9; padding:3px; text-align:left;}
    </style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" width="100%" >
    <tr>
        <td width="10%">用户名:</td>
        <td width="15%">
            <input type="text" value="" name="userids" id="userids" />
        </td>
        <td><input type="submit" style="width:60px; height:18px;" value="查询" id="search" class="button2" name="search" /></td>
    </tr>
</table>

</body>
</html>

------解决方案--------------------
不懂楼主要干啥?把TD里边的内容居左,你这个TR的宽度是多少?没具体说明,就只写了个table宽度100%,行的宽度没限制,而td的单位有用px这显得杂乱无章了点,单位必须统一,不然不一样的浏览器分辨率不一样。