冻结页面垂直滚动的前两行

Tom*_*Tom 11 html css angular

我实现了一个在角度上水平滚动的表,并且要求在垂直滚动时固定前两列。我创建了一个堆栈闪电来显示两个表。我要寻找的是,当用户滚动第二张表时,前两行即“合法类别名称”和“基金名称”应该是固定的。

我试图将以下类应用于相应的tds,但没有用

.stickyRows {
    position: sticky;
}
Run Code Online (Sandbox Code Playgroud)

这是堆叠闪电战

https://stackblitz.com/edit/angular-o2ukfs

.stickyRows {
    position: sticky;
}
Run Code Online (Sandbox Code Playgroud)
        th {
            padding: 7px;
            position: sticky;
            left: 0px;
            min-width: 250px;
            width: 250px;
            background-color: #f5f7f7;
        }
    
    
        td {
            padding: 7px;
            min-width: 250px;
            /* max-width: 300px; */
        }
    
        .fundClassesTable {
    
            table-layout: fixed;
        }
    
    
        .cellbgcolor {
            color: transparent;
        }
    
        .btn {}
    
        .tableItem {
            text-align: left;
            border-left: solid 1px lightgrey;
            border-top: solid 1px lightgrey;
            border-right: solid 1px lightgrey;
            border-bottom: solid 1px lightgrey;
    
        }
    
        .rowItem:hover {
            background-color: #f5f7f7;
        }
    
    
        label {
            margin-left: 0.5rem;
            vertical-align: middle
        }
    
    
        .panel-heading {
            color: black;
            border-color: #ddd;
            overflow: hidden;
            padding-top: 5px !important;
            padding-bottom: 5px !important;
        }
    
        .panel-heading .left-label {
            display: inline-block;
            padding-top: 5px !important;
    
        }
    
        .scrollClass {
            overflow-x: scroll;
            display: grid;
            overflow-y:hidden;
            height: 100%;
        }
    
        .panel-heading label {
            margin-bottom: 0px !important;
        }
    
        #FundClass tr:hover {
            background-color: #ECF0F1;
        }
    
        .headcol {
            position: absolute;
            min-width: 300px;
            max-width: 300px;
            width: 5em;
            left: 0;
            top: auto;
            border-top-width: 1px;
            /*only relevant for first row*/
            margin-top: -1px;
            /*compensate for top border*/
        }
    
        .headcol:before {
            content: 'Row ';
        }
    
        .collapsed {
            color: #d6630a;
            font-size: 22px;
            text-decoration: none;
            font-weight: bold;
        }
    
        .expanded {
            color: #d6630a;
            font-size: 22px;
            text-decoration: none;
            font-weight: bold;
    
        }
    
        .fixed-side {
            border: 1px solid #000;
            background: #eee;
            visibility: visible;
        }
    
    
        .card-body {
            flex: 1 1 auto;
            padding: 0px;
            margin: 10px 0;
            background-color: white;
    
        
        }
    
       
Run Code Online (Sandbox Code Playgroud)

ter*_*rtz 7

我希望这是您想要的:

GIF范例

app.component.css

/* Container should define how tall the scrollable content is */
.scrollClass{
  height: 500px;
}

/* tagetting the first <th>; to ensure <th> are scrolled along with <td> */
.fundClassesTable tr:nth-child(1) th{
  z-index: 3;
  position: sticky;
  position: -webkit-sticky;
  top: 2px;
}

/* target all <td> in the first row to be sticky */
.fundClassesTable tr:nth-child(1) td{
  color: red;
  position: sticky;
  position: -webkit-sticky;
  top: 2px;
  z-index: 2;
  background-color: white;
  font-weight: bold;
}

/* Same as above but with top property as 36px 
because the 2nd "row" is 36px from the top of <table> */
.fundClassesTable tr:nth-child(2) th{
  z-index: 3;
  position: sticky;
  position: -webkit-sticky;
  top: 38px;
}

.fundClassesTable tr:nth-child(2) td{
  color: red;
  position: sticky;
  position: -webkit-sticky;
  top: 38px;
  z-index: 2;
  background-color: white;
  font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)

分叉的Stackblitz

编辑:

里夫(Riv)的解决方案为我工作,但我遇到一个困扰的问题。在固定行中滚动时,可以看到固定行的间隙和固定行的边界之间可见的行数据,也看不到

可能不是最好的解决方案,但我会使用:: after伪选择器为粘滞表单元格创建背景,以在向下滚动时隐藏背景单元格。

.fundClassesTable tr:nth-child(1)::after{
  content: '';
  position: absolute;
  height: 71px;
  width: 96.7%;
  top: 55px;
  left: 19px;
  z-index: 1;
  background-color: white; //create a white background to cover your other cells when scrolled down
  border: solid 1px deeppink;
}
Run Code Online (Sandbox Code Playgroud)

  • 我在Windows上时使用[ShareX](https://github.com/ShareX/ShareX)。如果我使用的是Linux,则使用[Peek](https://github.com/phw/peek)。两者都是开源的屏幕捕获工具,可立即创建GIF。与他人合作时传达想法的绝佳工具=) (5认同)