第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

具有100%寬度的HTML表,Tbody內(nèi)有垂直滾動(dòng)

具有100%寬度的HTML表,Tbody內(nèi)有垂直滾動(dòng)

慕斯709654 2019-06-04 15:33:28
具有100%寬度的HTML表,Tbody內(nèi)有垂直滾動(dòng)我該怎么做<table>100%寬度,只放在里面<tbody>垂直卷軸的高度?vertical scroll inside tbodytable {    width: 100%;    display:block;}thead {    display: inline-block;    width: 100%;    height: 20px;}tbody {    height: 200px;    display: inline-block;    width: 100%;    overflow: auto;}  <table>  <thead>    <tr>    <th>Head 1</th>    <th>Head 2</th>    <th>Head 3</th>    <th>Head 4</th>    <th>Head 5</th>    </tr>  </thead>  <tbody>    <tr>    <td>Content 1</td>    <td>Content 2</td>    <td>Content 3</td>    <td>Content 4</td>    <td>Content 5</td>    </tr>  </tbody></table>
查看完整描述

3 回答

?
繁星淼淼

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊

在下面的解決方案中,表占父容器的100%,不需要絕對(duì)大小。它是純CSS,使用了Flex布局。

情況如下:

https://img1.sycdn.imooc.com//5cf61f2c0001aafd06740170.jpg

可能的缺點(diǎn):

  • 無(wú)論是否需要垂直滾動(dòng)條都是可見(jiàn)的;
  • 表格布局是固定的-列不根據(jù)內(nèi)容寬度調(diào)整大小(您仍然可以顯式地設(shè)置任何列寬);
  • 有一個(gè)絕對(duì)大小-滾動(dòng)條的寬度,對(duì)于我能夠檢查的瀏覽器大約是0.9em。

HTML(簡(jiǎn)稱(chēng)):

<div class="table-container">
    <table>
        <thead>
            <tr>
                <th>head1</th>
                <th>head2</th>
                <th>head3</th>
                <th>head4</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>content1</td>
                <td>content2</td>
                <td>content3</td>
                <td>content4</td>
            </tr>
            <tr>
                <td>content1</td>
                <td>content2</td>
                <td>content3</td>
                <td>content4</td>
            </tr>
            ...        </tbody>
    </table></div>

CSS,為了清晰起見(jiàn),省略了一些裝飾:

.table-container {
    height: 10em;}table {
    display: flex;
    flex-flow: column;
    height: 100%;
    width: 100%;}table thead {
    /* head takes the height it requires, 
    and it's not scaled when table is resized */
    flex: 0 0 auto;
    width: calc(100% - 0.9em);}table tbody {
    /* body takes all the remaining available space */
    flex: 1 1 auto;
    display: block;
    overflow-y: scroll;}table tbody tr {
    width: 100%;}table thead, table tbody tr {
    display: table;
    table-layout: fixed;}

在jsfiddle上的完整代碼

相同的代碼以較少的形式出現(xiàn),因此您可以將其混入:

.table-scrollable() {
  @scrollbar-width: 0.9em;
  display: flex;
  flex-flow: column;

  thead,
  tbody tr {
    display: table;
    table-layout: fixed;
  }

  thead {
    flex: 0 0 auto;
    width: ~"calc(100% - @{scrollbar-width})";
  }

  tbody {
    display: block;
    flex: 1 1 auto;
    overflow-y: scroll;

    tr {
      width: 100%;
    }
  }}


查看完整回答
反對(duì) 回復(fù) 2019-06-04
  • 3 回答
  • 0 關(guān)注
  • 868 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)