2

我有一张这样的表(包括引导程序):

<table class="table table-hover">
   <tbody>
      <tr><td>Head1</td><td>content1.1</td></tr>
      <tr><td></td><td>content1.2</td></tr>
      <tr><td></td><td>content1.3</td></tr>
      <tr><td>Head2</td><td>content2</td></tr>
      <tr><td>Head3</td><td>content3</td></tr>
   </tbody>
</table>

我希望表格线在其容器的整个宽度上,但带有标题和内容的两个单元格应该居中。我试图在图像中描述它:

我不能在这里上传图片,所以我在其他地方做了:

更多描述见图片

4

3 回答 3

7

我只显示了两行 ( tr)。您可以根据需要添加任意数量的行。

HTML:

    <table class="table table-hover">
   <tbody>
      <tr>
         <td>&nbsp;</td>
         <td>Head1</td>
         <td>content1</td>
         <td>&nbsp;</td>
      </tr> 
      <tr>
         <td>&nbsp;</td>
         <td>Head2</td>
         <td>content2</td>
         <td>&nbsp;</td>
      </tr>      
   </tbody>
</table>

CSS:

table.table.table-hover{ width:100%; }
table.table.table-hover tr td{ width:25% }

演示

希望你会发现这很有用:)

于 2013-05-15T06:46:00.560 回答
1

这是您可以尝试的代码,如果您有任何css问题,请告诉我

.wid50{width:50%;}


<table class="table table-hover" width="100%" cellpadding="0" cellspacing="0">
   <tbody>
      <tr>
         <td class="wid50">Head1</td>
         <td class="wid50">content1.1</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>content1.2</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>content1.3</td>
      </tr>
      <tr>
        <td>Head2</td>
        <td>content2</td>
      </tr>
      <tr>
        <td>Head3</td>
        <td>content3</td>
      </tr>
   </tbody>
</table>
于 2013-05-15T06:21:29.103 回答
1

请根据您的图像也检查一下

<table class="table table-hover" width="100%" cellpadding="0" cellspacing="0">
   <tbody>
      <tr>
        <td class="wid2">&nbsp;</td>
        <td class="wid1">Head1</td>
        <td class="wid1">content1.1</td>
        <td class="wid2">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>content1.2</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>content1.3</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
      <td>&nbsp;</td>
        <td>Head2</td>
        <td>content2</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>Head3</td>
        <td>content3</td>
        <td>&nbsp;</td>
      </tr>
   </tbody>
</table>

这是CSS

table.table tr td{border-bottom:1px solid #000;}
.wid1{width:20%;}
.wid2{width:30%;}
于 2013-05-15T06:29:51.213 回答