簡體   English   中英

調整表格中的列寬(CSS / HTML)

[英]Adjusting column width in Table (CSS/HTML)

我一直在嘗試使移動設備上的列寬變為50%,但我嘗試過的所有方法均無效。 這是css。

@media (max-width: 768px) {

#customTable tbody { float: left; }
#customTable thead { float: left; }
#customTable thead { min-width: 120px }
#customTable td { display: block }
#customTable th { display: block }
#customTable {table-layout: fixed;}
#customTable td {width: 50%;}
#customTable td {height: 20px; overflow: hidden;}
#customTable div {height: 20px;overflow: hidden;}
}

這是HTML

 <div class="table">
<table id="customTable" class="table" style="width: 100%">
<thead>
    <tr>
        <th><LABEL>Test 1</LABEL></td>
        <th><LABEL>Test 2</LABEL></td>
        <th><LABEL>Test 3</LABEL></td>
        <th><LABEL>Test 4</LABEL></td>
    </tr>
    </thead>
    <tr>                
        <td><LABEL>Test</LABEL></td>
        <td><LABEL>Test</LABEL></td>
        <td><LABEL>Test</LABEL></td>
        <td><LABEL>Test</LABEL></td>
    </tr>

</table>
</div>

如果要使用表調整列寬,則實際上需要告訴它不再充當表。

例如,在#customTable td上使用display:blockwidth:50%並從那里開始工作,就好像它們是block元素一樣。

如果要調整列的寬度,則應調整thead中 th的寬度。

這對我有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM