2012-04-10 58 views
2

我在表中浮动标题有问题。我的标题应该是colspan="2",但是当我将float:left设置为td元素“标题”时,colspan停止工作。我想是这样的:表和浮动

+-------------------------------------------------+ 
|Header headher header header      | 
+-------------------------------------------------+ 
|Something  | Something      | 
+-------------------------------------------------+ 

但我得到这个:

enter image description here

我的代码:

<table border="1"> 
    <thead> 
     <tr> 
      <th colspan="2" style="float: left;">Header header</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>Something</td> 
      <td>Something</td> 
     </tr> 


    </tbody> 
</table> 
+3

所以不要浮动......问题解决:) – CyberDude 2012-04-10 20:00:12

+0

但它似乎中心。如何将它移动到左侧? – sundaysloth 2012-04-10 20:04:39

+0

你的意思是里面的文字居中?使用'style =“text-align:left;”'而不是浮动。 – CyberDude 2012-04-10 20:06:00

回答

7

不要使用float:left,使用text-align:left

<table border="1"> 
    <thead> 
     <tr> 
      <th colspan="2" style="text-align: left;">Header header</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>Something</td> 
      <td>Something</td> 
     </tr> 

    </tbody> 
</table> 

jsFiddle example