2013-07-18 168 views
0

我想要使用div来实现类似下面的表格的相同结果,这样我可以使其响应并调整每个表格行的列数。 (例如,在第一行有3个响应列,然后在第二行有4个响应列)。我也想避免在单独的单词中写单个字div模拟的响应式列表

有没有办法做到这一点?

这里是当前表

<table> 
    <thead> 
     <tr> 
      <th class="short-column">Short Column</th> <!-- th sets the width --> 
      <th class="short-column">Short Column</th> <!-- th sets the width --> 
      <th class="long-column">Long Column</th> <!-- th sets the width --> 
     </tr> 
    </thead> 

    <tbody> 
     <tr> 
      <td class="lite-gray">Short Column</td> <!-- td inherits th width --> 
      <td class="lite-gray">Short Column</td> <!-- td inherits th width --> 
      <td class="gray">Long Column</td> <!-- td inherits th width --> 
     </tr> 
    </tbody> 
</table> 


table { table-layout: fixed; border-collapse: collapse; border-spacing: 0; width: 100%; } 

.short-column { background: yellow; width: 30%; } 
.long-column { background: lime; width: 40%; } 

.lite-gray { background: #f2f2f2; } 
.gray { background: #cccccc; } 

Here is a fiddle

是否有可能使用类似

<table width="100%" border="0" cellspacing="0" cellpadding="4"> 
      <tr> 
     <td> 
       <!--<div>THREE COLUMNS</div>--> 
      </td> 
     </tr> 
      <tr> 
     <td> 
       <!--<div>FOUR COLUMNS?</div>--> 
      </td> 
     </tr> 
</table> 
+0

是这样的吗? http://jsfiddle.net/TdmkG/1/ –

+0

是的,究竟需要什么。您能否在此发布代码,以便我可以接受您的答案,谢谢 – cMinor

回答

2

如果你插入浮动的div到您的td元素,你可以创建相同的布局:

<table width="100%" border="1" cellspacing="0" cellpadding="4"> 
    <tr> 
     <td> 
      <!--<div>THREE COLUMNS</div>--> 
      <div class="three"></div> 
      <div class="three"></div> 
      <div class="half"></div> 
     </td> 
    </tr> 
    <tr> 
     <td> 
      <!--<div>FOUR COLUMNS?</div>--> 
      <div class="four"></div> 
      <div class="four"></div> 
      <div class="four"></div> 
      <div class="four"></div> 
     </td> 
    </tr> 
</table> 

然后,只需添加一些宽度的样式,你就全部设置!

演示:http://jsfiddle.net/TdmkG/1/