我正在使用CSS display
property和table
,table-row
和table-cell
值來以表格的形式佈局我的文檔。使第二個表格中的單元格的寬度等於第一個表格中的單元格的寬度?
通常情況下(你可以在代碼中看到)的細胞的表的大小有關,包含(直到我們提供硬編碼維度值的內容。
但我想table-cell
小號在第二個(依此類推)table-row
與第一個table-row
對應的table-cell
具有相同的寬度。因此,第一行中第一個table-cell
的寬度與第一個table-row
中第一個table-cell
的寬度相同。是否有可能?
我想要這樣做,而不必在第二個和後續的table-row
s中添加pixel
margin
或padding
等屬性。我只是想讓它上面的單元格的width
。
所以最後,列的寬度將等於列中最寬的單元格的寬度。
我該怎麼做?
Here is the fiddle.在代碼中,三行有不同的顏色。
CODE:
<div style="display:table;">
<div style="background-color:#d9a4f4; display:table-row;">
<label style="display:table-cell; padding-left:10px; padding-right:10px;">Inferrable</label>
<label style="display:table-cell; padding-left:10px; padding-right:10px;">Not inferrable</label>
</div>
<div style="background-color:#7cbfdd; display:table-row;">
<input type="radio" name="radio_group1" value="0" style="display:table-cell;">
<input type="radio" name="radio_group1" value="0" style="display:table-cell;">
<label style="display:table-cell;">I am the label for the first group of radio buttons. I am the label for the first group of radio buttons. I am the label for the first group of radio buttons. I am the label for the first group of radio buttons. I am the label for the first group of radio buttons. </label>
</div>
<div style="background-color:#e8c277; display:table-row;">
<input type="radio" name="radio_group2" value="0" style="display:table-cell;">
<input type="radio" name="radio_group2" value="1" style="display:table-cell;">
<label style="display:table-cell;">I am the label for the second group of radio buttons. I am the label for the second group of radio buttons. I am the label for the second group of radio buttons. </label>
</div>
</div>
哈啊!不要這樣做。如果你想讓它們完全匹配或使用表格佈局(*咳嗽*) – 2014-08-27 13:28:41
不要使用內聯樣式,請在單獨的CSS文件中定義樣式。 – Dan 2014-08-27 13:30:18
您每行的單元格數量不正確 - 如果您希望它們相等,則它們應匹配,因爲display-table沒有像colspan這樣的內容。因爲你的數據看起來好像它可以被分類爲表格,所以你應該使用一個適當的表格,並在第一行設置'th'和'scope'。 – Pete 2014-08-27 13:33:33