javascript - 如何将我的 td 与等宽对齐?

标签 javascript jquery css html

这是我的 html 代码:http://jsfiddle.net/Udxyb/427/

在下面的代码中..在每一列(第 1 节、第 2 节、第 3 节、第 4 节)下,我想要两个相等的列,如果输入数据很长,这些列不应变化。 相反,两列的宽度必须保持不变而不是增加。这可能吗???

<table id="main_table" style="width:100%">
    <thead>
        <tr class="firstline">
            <th colspan="2">Column1</th>
            <th colspan="2">Column2</th>
            <th colspan="2">Column3</th>
            <th colspan="2">Column4</th>
        </tr>
    </thead>
    <tbody>
        <tr style="width:1002px; background-color:green; color:white">
            <td  colspan="2" class="flip" style="width:250px;"> Section 1 </td>
              <td  colspan="2" class="flip" style="width:250px;"> Section 1 </td>
             <td  colspan="2" class="flip" style="width:250px;"> Section 1 </td>
             <td  colspan="2" class="flip" style="width:250px;"> Section 1 </td>
        </tr>
    </tbody>
    <tbody class="section">
        <tr>
            <td style="width:125px;">item 111sdfgadgrfag</td>
            <td>item 112</td>
            <td>item 113</td>
            <td>item 114</td>
            <td>item 115</td>
            <td>item 116</td>
            <td>item 117</td>
            <td>item 118dfgdfgdfgdfgg</td>
      </tr>
        <tr>
            <td colspan="2">item 121</td>
            <td colspan="2">item 122</td>
            <td colspan="2">item 123</td>
            <td colspan="2">item 124</td>
        </tr>
        <tr>
            <td colspan="2">item 131</td>
            <td colspan="2">item 132</td>
            <td colspan="2">item 133</td>
            <td colspan="2">item 134</td>
        </tr>
    </tbody>
    <tbody>
        <tr style="background-color:green; color:white">
            <td  colspan="2" class="flip" style="width:250px;"> Section 2 </td>
             <td  colspan="2" class="flip" style="width:250px;"> Section 2 </td>
             <td  colspan="2" class="flip" style="width:250px;"> Section 2 </td>             <td  colspan="2" class="flip" style="width:250px;"> Section 2 </td>
        </tr>
    </tbody>
    <tbody class="section">
        <tr>
            <td colspan="2">item 211</td>
            <td colspan="2">item 212</td>
            <td colspan="2">item 213</td>
            <td colspan="2">item 214</td>
        </tr>
        <tr>
            <td colspan="2">item 221</td>
            <td colspan="2">item 222</td>
            <td colspan="2">item 223</td>
            <td colspan="2">item 224</td>
        </tr>
        <tr>
            <td colspan="2">item 231</td>
            <td colspan="2">item 232</td>
            <td colspan="2">item 233</td>
            <td colspan="2">item 234</td>
        </tr>
    </tbody>
    <tbody>
        <tr style="background-color:green; color:white">
             <td  colspan="2" class="flip" style="width:250px;"> Section 3 </td>
             <td  colspan="2" class="flip" style="width:250px;"> Section 3 </td>
             <td  colspan="2" class="flip" style="width:250px;"> Section 3 </td>
             <td  colspan="2" class="flip" style="width:250px;"> Section 3 </td>
        </tr>
    </tbody>
    <tbody class="section">
        <tr>
            <td colspan="2">item 311</td>
            <td colspan="2">item 312</td>
            <td colspan="2">item 313</td>
            <td colspan="2">item 314</td>
        </tr>
        <tr>
            <td colspan="2">item 321</td>
            <td colspan="2">item 322</td>
            <td colspan="2">item 323</td>
            <td colspan="2">item 324</td>
        </tr>
        <tr>
            <td colspan="2">item 331</td>
            <td colspan="2">item 332</td>
            <td colspan="2">item 333</td>
            <td colspan="2">item 334</td>
        </tr>
    </tbody>
</table>

最佳答案

写:

#main_table{table-layout:fixed;}

Updated fiddle here.

关于javascript - 如何将我的 td 与等宽对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22348645/

相关文章:

javascript - Ajax调用php未找到,404错误

javascript - jQuery:以下代码块中比较的含义是什么 - callback && function() {callback.call();}

jquery - 无法调用 ck-editor textarea(未捕获类型错误 : $(. ..)。ckeditor 不是函数)

css - 将图像宽度调整为容器大小的 100% - 图像下方的持久空间

javascript - Highcharts 将小数值四舍五入为 0。如何避免这种情况?

javascript - 使用 puppeteer 来使用 CSS @media 规则

jquery - 无法在 qtip 中使用 "style option"应用样式

c# - 无法加载文件或程序集 'AjaxMin,版本 = 4.97.4951.28478,

javascript - 为什么我的网站可以使用 Safari,而不是 FireFox 或 IE?

jquery - 为什么我必须使用 $ ('#id' )[0].srollHeight 而不是 $ ('#id' ).srollHeight