th固定 td滾動的表格實現


為什么這樣?

體驗好

原理

通過兩個表格,使其th td 對應,產生一種錯覺。

代碼

1.html

<div class="content">
    <div class="table-head">
    <table>
        <colgroup>
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
        </colgroup>
        <thead>
            <tr>
            <th>日期</th>
            <th >單價</th>
            <th >數量</th>
            <th >小計</th>
            </tr>
        </thead>
    </table>
    </div>
    <div class="table-body">
    <table>
        <colgroup>
        	<col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
        </colgroup>
        <tbody>
        	{loop $data $k $v}
	        <tr>
	          <td scope="row">{$v['date']}</td>
	          <td>{if isset($v['discount'])}¥{$v['price']}<span style="text-decoration:line-through;color:#999999;">¥{$v['oprice']}</span>{else}¥{$v['price']}{/if}</td>
	          <td>{$v['roomnum']}</td>
	          <td>¥{$v['subtotal']}</td>
	        </tr>
	        {/loop}
	        </tbody>
    </table>
    </div>
	
    <div class="total">共&nbsp;{$checknum}&nbsp;晚 合計¥{$allprice}</div>

</div>

2.css

<style>
		.table-head{padding-right:17px;background-color:#999;color:#000;}
		.table-body{width:100%; height:390px;overflow-y:scroll;}
		.table-head table,.table-body table{width:100%;}
		.table-head tr,.table-body tr{line-height: 35px;}
		.table-head th,.table-body td{text-align: center;}
		.table-body table tr:nth-child(2n+1){background-color:#f2f2f2;}
		.total {
			float:right;
			padding-right: 20px;
			margin-top:5px;
		}
</style>

核心

<colgroup>
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
            <col style="width: 25%;" /><col />
</colgroup>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 表格table,th,tr,td區分以及屬性 table的td、th的一些樣式問題(寬度,邊框,滾動條,多行多列的表頭thead固定) table表格 td設置固定寬度 表頭固定內容可滾動表格的3種實現方法 【css】table標簽內的td、th如何設置固定寬度,而不是自適應? HTML 表格 實現表格tbody內滾動 html - table 表格不被撐開,td某些列寬度固定某些列自適應 html - table 表格不被撐開,td某些列寬度固定某些列自適應
 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM
table表格固定前幾列,其余的滾動