Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 成人国产精品久久久免费,久久精品嫩草影院免费看,久久免费视频网

          整合營(yíng)銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          (首列凍結(jié))通過(guò)CSS來(lái)實(shí)現(xiàn)HTML表格的固定首列和

          (首列凍結(jié))通過(guò)CSS來(lái)實(shí)現(xiàn)HTML表格的固定首列和橫向滾動(dòng)效果

          方法一:sticky 方式

          核心樣式

                  .pure-table-wrapper-div {
                      overflow-x: scroll;
                  }
              
                  table.pure-table th:first-child,
                  table.pure-table td:first-child {
                      position: sticky;
                      left: 0;
                      z-index: 1;
                      background-color: aliceblue;
                  }
          

          解釋

          .pure-table-wrapper-div:

          這個(gè)類名應(yīng)用于包裹表格的 div 元素。它的樣式規(guī)則如下:

          overflow-x: scroll;: 當(dāng)內(nèi)容寬度超出容器寬度時(shí),顯示水平滾動(dòng)條。這允許用戶在需要時(shí)水平滾動(dòng)查看表格的所有列。


          示例 HTML 結(jié)構(gòu):


          <div class="pure-table-wrapper-div"> <table class="pure-table"> <!-- 表格內(nèi)容 --> </table> </div>


          table.pure-table th:first-child, table.pure-table td:first-child: 這兩個(gè)選擇器分別針對(duì) .pure-table 類的表格中的第一個(gè)表頭單元格(<th>)和第一個(gè)數(shù)據(jù)單元格(<td>)。


          它們定義的樣式規(guī)則如下:


          position: sticky;: 使用黏性定位。黏性定位元素在滾動(dòng)時(shí)會(huì)根據(jù)設(shè)置的 top、bottom、left 或 right 屬性值在特定位置 "粘附"。在本例中,由于定義了 left: 0;,這些元素會(huì)在左側(cè)邊緣粘附。 left: 0;: 在元素滾動(dòng)到視口左側(cè)邊緣時(shí)使其粘附。與 position: sticky; 結(jié)合使用。


          z-index: 1;: 設(shè)置元素的堆疊順序。值越大,元素越靠前。在這種情況下,將第一個(gè)單元格設(shè)置為 z-index: 1 可確保它在其他表格單元格之上。


          background-color: aliceblue;: 為匹配的單元格設(shè)置背景顏色。這可以增強(qiáng)視覺(jué)效果,使粘附的單元格與其他單元格區(qū)分開(kāi)。

          這段 CSS 代碼的主要目的是實(shí)現(xiàn)表格的水平滾動(dòng),并固定第一列,使其在水平滾動(dòng)時(shí)保持可見(jiàn)。同時(shí),為第一列的單元格設(shè)置了背景顏色以增強(qiáng)視覺(jué)效果。


          總的來(lái)說(shuō)是:


          使用 position: sticky; 來(lái)固定第一列。在 table.pure-table th:first-child 中設(shè)置了 position: sticky; 和 left: 0;,并將 z-index 設(shè)為 1,以確保第一列在滾動(dòng)時(shí)會(huì)固定在屏幕上方。

          完整代碼

          <!DOCTYPE html>
          <html lang="zh-CN">
          
          <head>
              <meta charset="UTF-8">
              <link rel="stylesheet" href="./purecss@3.0.0.css">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>文檔</title>
              <style>
                  .pure-table-wrapper-div {
                      overflow-x: scroll;
                  }
              
                  table.pure-table th:first-child,
                  table.pure-table td:first-child {
                      position: sticky;
                      left: 0;
                      z-index: 1;
                      background-color: aliceblue;
                  }
              </style>
          </head>
          
          <body>
              <div class="pure-table-wrapper-div">
                  <table class="pure-table">
                      <thead>
                          <tr>
                              <th>#</th>
                              <th>品牌</th>
                              <th>型號(hào)</th>
                              <th>隨機(jī)字符串</th>
                              <th>說(shuō)明</th>
                          </tr>
                      </thead>
                      <tbody>
                          <tr>
                              <td>1</td>
                              <td>本田</td>
                              <td>雅閣</td>
                              <td>2009-QWERTYUIOPASDFGHJKLZXCVBNM</td>
                              <td>這是一段中文說(shuō)明文字。</td>
                          </tr>
                          <tr>
                              <td>2</td>
                              <td>豐田</td>
                              <td>凱美瑞</td>
                              <td>2012-QWERTYUIOPASDFGHJKLZXCVBNM</td>
                              <td>這是一段中文說(shuō)明文字。</td>
                          </tr>
                          <tr>
                              <td>3</td>
                              <td>現(xiàn)代</td>
                              <td>領(lǐng)動(dòng)</td>
                              <td>2010-QWERTYUIOPASDFGHJKLZXCVBNM</td>
                              <td>這是一段中文說(shuō)明文字。</td>
                          </tr>
                      </tbody>
                  </table>
              </div>
          </body>
          
          </html>
          

          中文不換行

          要去除表格中最后一列中文的換行效果,可以使用 CSS 的 white-space 屬性,將其設(shè)置為 nowrap,這樣文字就不會(huì)自動(dòng)換行了。

          添加了以下 CSS 樣式:

          table.pure-table td:last-child,
          table.pure-table th:last-child {
              white-space: nowrap;
          }
          

          這樣,最后一列中文就不會(huì)自動(dòng)換行了。其中 table.pure-table td:last-child 和 table.pure-table th:last-child 選擇器用于指定表格中的最后一列單元格,white-space: nowrap; 則是將 white-space 屬性設(shè)置為 nowrap,禁止其自動(dòng)換行。

          小結(jié)

          position: sticky 是 CSS 中的一種定位方式,可以實(shí)現(xiàn)元素在滾動(dòng)時(shí)固定在屏幕上,直到其滾動(dòng)到指定位置。相對(duì)于 position: fixed,position: sticky 有以下優(yōu)點(diǎn)和缺點(diǎn):

          優(yōu)點(diǎn):

          1. 不會(huì)脫離文檔流,因此不會(huì)影響其他元素的布局和位置;
          2. 可以在頁(yè)面滾動(dòng)到指定位置時(shí)自動(dòng)固定,無(wú)需手動(dòng)計(jì)算位置;
          3. 可以在滾動(dòng)到指定位置后自動(dòng)取消固定,不會(huì)一直占據(jù)屏幕空間,避免了 position: fixed 的潛在問(wèn)題;
          4. 可以在固定元素上設(shè)置 z-index 屬性,與其他元素進(jìn)行層級(jí)控制。

          缺點(diǎn):

          1. 兼容性問(wèn)題:position: sticky 不是所有瀏覽器都支持,特別是在 IE11 及以下版本中不支持;
          2. 在某些情況下可能會(huì)存在性能問(wèn)題,尤其是在滾動(dòng)時(shí)固定的元素較多時(shí),可能會(huì)導(dǎo)致卡頓和性能下降;
          3. 在某些情況下可能會(huì)存在滾動(dòng)到指定位置時(shí)出現(xiàn)抖動(dòng)的問(wèn)題,需要通過(guò)對(duì)元素和容器的尺寸、位置等進(jìn)行調(diào)整來(lái)解決。

          綜上所述,position: sticky 是一種靈活且易用的定位方式,具有很多優(yōu)點(diǎn),但在兼容性和性能方面有一些缺點(diǎn)需要注意。如果要在項(xiàng)目中使用 position: sticky,需要在兼容性和性能方面進(jìn)行綜合考慮,以確保其正常運(yùn)行和良好的用戶體驗(yàn)。

          【兼容性好】postion 的 absolute 方式【需要指定首列寬度】

          核心樣式

                  .pure-table-wrapper-div {
                      overflow-x: scroll;
                      margin-left: 5em;
                  }
                
                  table.pure-table tr td:first-child,
                  table.pure-table tr th:first-child {
                      position: absolute;
                      width: 5em;
                      left: 0;
                  }
          

          解釋

          這段 CSS 代碼主要是為了實(shí)現(xiàn)固定表格首列和橫向滾動(dòng)效果,并且在表格首列添加了固定的寬度。

          首先,.pure-table-wrapper-div 是一個(gè)包裹表格的 div 元素,通過(guò)設(shè)置 overflow-x: scroll,實(shí)現(xiàn)了橫向滾動(dòng)的效果。同時(shí),通過(guò)設(shè)置 margin-left: 5em,在左側(cè)添加了 5em 的空白,使得表格不會(huì)緊貼在頁(yè)面最左側(cè),美觀性更好。

          接著,table.pure-table tr td:first-child 和 table.pure-table tr th:first-child 選擇器用于選中表格中的第一列單元格,使用 position: absolute 將其從文檔流中脫離,并使用 width: 5em 指定其寬度為 5em,然后通過(guò) left: 0 將其固定在表格最左側(cè)。

          這樣,表格的首列就被固定在了左側(cè),不會(huì)隨著表格的滾動(dòng)而移動(dòng),同時(shí)也添加了固定的寬度,使得表格整體更加美觀和易讀。

          總的來(lái)說(shuō),這段 CSS 代碼實(shí)現(xiàn)了表格的固定首列和橫向滾動(dòng)效果,同時(shí)也為表格首列添加了固定的寬度,提高了表格的可讀性和美觀性。

          完整代碼

          <!DOCTYPE html>
          <html lang="en">
          
          <head>
              <meta charset="UTF-8">
              <link rel="stylesheet" href="./purecss@3.0.0.css">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>Document</title>
          </head>
          
          <body>
              <style>
                  .pure-table-wrapper-div {
                      overflow-x: scroll;
                      margin-left: 5em;
                  }
                
                  table.pure-table tr td:first-child,
                  table.pure-table tr th:first-child {
                      position: absolute;
                      width: 5em;
                      left: 0;
                  }
              </style>
              <div class="pure-table-wrapper-div">
                  <table class="pure-table">
                      <thead>
                          <tr>
                              <th>#</th>
                              <th>Make</th>
                              <th>Model</th>
                              <th>隨機(jī)數(shù)</th>
                          </tr>
                      </thead>
                      <tbody>
                          <tr>
                              <td>1</td>
                              <td>Honda</td>
                              <td>Accord</td>
                              <td>2009-QWERTYUIOPASDFGHJKLZXCVBNM</td>
                          </tr>
                          <tr>
                              <td>2</td>
                              <td>Toyota</td>
                              <td>Camry</td>
                              <td>2012-QWERTYUIOPASDFGHJKLZXCVBNM</td>
                          </tr>
                          <tr>
                              <td>3</td>
                              <td>Hyundai</td>
                              <td>Elantra</td>
                              <td>2010-QWERTYUIOPASDFGHJKLZXCVBNM</td>
                          </tr>
                      </tbody>
                  </table>
              </div>
          </body>
          
          </html>
          

          小結(jié)

          CSS 中的 position: absolute 定位方式可以讓元素脫離文檔流,并相對(duì)于它的最近的非 static 定位祖先元素進(jìn)行定位。相對(duì)于其他定位方式,position: absolute 有以下優(yōu)點(diǎn)和缺點(diǎn):

          優(yōu)點(diǎn):

          1. 可以精確控制元素的位置,可以在任何位置放置元素;
          2. 可以與其他元素重疊,實(shí)現(xiàn)復(fù)雜的布局效果;
          3. 可以讓元素脫離文檔流,不會(huì)影響其他元素的布局和位置;
          4. 可以通過(guò)設(shè)置 z-index 屬性進(jìn)行層級(jí)控制。

          缺點(diǎn):

          1. 不會(huì)占據(jù)原來(lái)的空間,可能會(huì)導(dǎo)致其他元素填補(bǔ)其位置,影響頁(yè)面布局;
          2. 定位時(shí)需要手動(dòng)指定位置,不如其他定位方式使用方便;
          3. 在某些情況下,可能會(huì)出現(xiàn)元素位置計(jì)算錯(cuò)誤的問(wèn)題,需要仔細(xì)調(diào)整位置和尺寸。

          綜上所述,position: absolute 是一種靈活且強(qiáng)大的定位方式,可以實(shí)現(xiàn)很多獨(dú)特的布局效果,但需要注意它可能會(huì)對(duì)頁(yè)面布局和元素位置產(chǎn)生影響。在使用時(shí),需要根據(jù)具體情況進(jìn)行綜合考慮,并在保證頁(yè)面布局和元素位置正確的前提下,盡可能地利用其優(yōu)點(diǎn)實(shí)現(xiàn)更好的頁(yè)面效果。

          CSS table表格 thead固定 tbody滾動(dòng)效果

          由于項(xiàng)目需要,在表格中,當(dāng)數(shù)據(jù)量越來(lái)越多時(shí),就會(huì)出現(xiàn)滾動(dòng)條,而在滾動(dòng)的過(guò)程中,默認(rèn)情況下表格頭部會(huì)跟著表格內(nèi)容一起滾動(dòng),導(dǎo)致看不到頭部對(duì)應(yīng)的字段名,影響體驗(yàn)效果!

          實(shí)現(xiàn)思路:

          將內(nèi)容要滾動(dòng)的區(qū)域控制在 tbody 標(biāo)簽中添加 overflow-y: auto; 樣式,給 tr 標(biāo)簽添加 table-layout:fixed; (這是核心)樣式,由于 tbody 有了滾動(dòng)條后,滾動(dòng)條也要占位,又會(huì)導(dǎo)致 tbody 和 thead 不對(duì)齊,所以在設(shè)置 tbody 的寬度時(shí)要把滾動(dòng)條的寬度也加上【如果不想顯示滾動(dòng)條的話,可以把滾動(dòng)條的寬度設(shè)置為0px,滾動(dòng)條就沒(méi)有了。

          下面是效果圖,具體完整實(shí)例代碼也在下面:


          完整實(shí)例代碼:

          <!DOCTYPE html>
          <html lang="en">
           
          <head>
              <meta charset="UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <meta http-equiv="X-UA-Compatible" content="ie=edge">
              <title>純CSS table表格 thead固定 tbody滾動(dòng)</title>
              <style>
                  .table-box {
                      margin: 100px auto;
                      width: 1024px;
                  }
           
                  /* 滾動(dòng)條寬度 */
                  ::-webkit-scrollbar {
                      width: 8px;
                      background-color: transparent;
                  }
           
                  /* 滾動(dòng)條顏色 */
                  ::-webkit-scrollbar-thumb {
                      background-color: #27314d;
                  }
           
                  table {
                      width: 100%;
                      border-spacing: 0px;
                      border-collapse: collapse;
                  }
           
                  table caption{
                      font-weight: bold;
                      font-size: 24px;
                      line-height: 50px;
                  }
           
                  table th, table td {
                      height: 50px;
                      text-align: center;
                      border: 1px solid gray;
                  }
           
                  table thead {
                      color: white;
                      background-color: #38F;
                  }
           
                  table tbody {
                      display: block;
                      width: calc(100% + 8px); /*這里的8px是滾動(dòng)條的寬度*/
                      height: 300px;
                      overflow-y: auto;
                      -webkit-overflow-scrolling: touch;
                  }
           
                  table tfoot {
                      background-color: #71ea71;
                  }
           
                  table thead tr, table tbody tr, table tfoot tr {
                      box-sizing: border-box;
                      table-layout: fixed;
                      display: table;
                      width: 100%;
                  }
           
                  table tbody tr:nth-of-type(odd) {
                      background: #EEE;
                  }
           
                  table tbody tr:nth-of-type(even) {
                      background: #FFF;
                  }
           
                  table tbody tr td{
                      border-bottom: none;
                  }
           
              </style>
          </head>
           
          <body>
              <section class="table-box">
                  <table cellpadding="0" cellspacing="0">
                      <caption>純CSS table表格 thead固定 tbody滾動(dòng)</caption>
                      
                      <thead>
                          <tr>
                              <th>序 號(hào)</th>
                              <th>姓 名</th>
                              <th>年 齡</th>
                              <th>性 別</th>
                              <th>手 機(jī)</th>
                          </tr>
                      </thead>
           
                      <tbody>
                          <tr>
                              <td>001</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>女</td>
                              <td>Mobile</td>
                          </tr>
                          <tr>
                              <td>002</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>男</td>
                              <td>Mobile</td>
                          </tr>
                          <tr>
                              <td>003</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>女</td>
                              <td>Mobile</td>
                          </tr>
                          <tr>
                              <td>004</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>男</td>
                              <td>Mobile</td>
                          </tr>
                          <tr>
                              <td>005</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>女</td>
                              <td>Mobile</td>
                          </tr>
                          <tr>
                              <td>006</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>男</td>
                              <td>Mobile</td>
                          </tr>
                          <tr>
                              <td>007</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>女</td>
                              <td>Mobile</td>
                          </tr>
                          <tr>
                              <td>008</td>
                              <td>Name</td>
                              <td>28</td>
                              <td>男</td>
                              <td>Mobile</td>
                          </tr>
                      </tbody>
           
                      <tfoot>
                          <tr>
                              <td colspan="5">【table,thead,tbody,tfoot】 colspan:合并行, rowspan:合并列 </td>
                          </tr>
                      </tfoot>
                  </table>
              </section>
          </body>
           
          </html>

          我自己是一名從事了多年開(kāi)發(fā)的web前端老程序員,目前辭職在做自己的web前端私人定制課程,今年年初我花了一個(gè)月整理了一份最適合2019年學(xué)習(xí)的web前端學(xué)習(xí)干貨,各種框架都有整理,送給每一位前端小伙伴,想要獲取的可以關(guān)注我的頭條號(hào)并在后臺(tái)私信我:前端,即可免費(fèi)獲取。



          原文鏈接:https://blog.csdn.net/muguli2008/article/details/103787152

          ss

          * {
              margin: 0;
              padding: 0;
          }
          .virtual-scroll-viewport {
              position: relative;
              width: 240px;
              height: 300px;
              margin: 150px auto 0;
              overflow: auto;
              will-change: scroll-position;
              border: 1px solid #aaaaaa;
          }
          /* 撐開(kāi)高度 */
          .virtual-scroll-spacer {
              position: absolute;
              top: 0;
              left: 0;
              right: 0;
          }
          .virtual-scroll-list {
              position: absolute;
              top: 0;
              left: 0;
              right: 0;
          }
          .virtual-scroll-item {
              height: 50px;
              padding-left: 15px;
              line-height: 50px;
          }
          .virtual-scroll-item:nth-child(2n) {
              background: #f6f8fa;
          }

          html

          <div class="virtual-scroll-viewport">
              <div class="virtual-scroll-spacer"></div>
              <div class="virtual-scroll-list"></div>
          </div>
          
          

          js


          主站蜘蛛池模板: 乱人伦一区二区三区| 亚洲AV无码一区二区三区电影| 无码人妻一区二区三区兔费| 无遮挡免费一区二区三区| 91video国产一区| 亚洲一区二区三区在线视频| 日韩AV无码一区二区三区不卡| 亚洲av鲁丝一区二区三区| 国产精品亚洲高清一区二区| 精品3d动漫视频一区在线观看| 亚洲成AV人片一区二区密柚 | 亚洲一区二区三区免费| 风间由美在线亚洲一区| 亚洲色无码专区一区| 亚洲AV无码一区二区三区牛牛| 无码一区二区三区老色鬼| 国产综合一区二区| 日本不卡在线一区二区三区视频| 中文字幕精品亚洲无线码一区应用| 日本精品一区二区三区四区| 国产一区二区三区手机在线观看| 国产精品无码一区二区三区毛片 | 国产高清视频一区二区| 国产精品无码一区二区在线 | 色狠狠色狠狠综合一区| 中文字幕一区二区三区精彩视频| 亚洲国产一区二区三区青草影视| 亚洲一区二区在线免费观看| 久久久久成人精品一区二区| 农村乱人伦一区二区| 中文字幕视频一区| 天堂Av无码Av一区二区三区| 国产福利一区视频| 国产精品 一区 在线| 国产成人一区二区三区在线| 亚洲图片一区二区| 精品亚洲AV无码一区二区| 午夜视频在线观看一区| 高清在线一区二区| 久久久久久免费一区二区三区| 久久精品国产第一区二区三区|