2 回答
TA贡献1830条经验 获得超3个赞
您需要在这里定位:粘性:
.coursesSection--slider {
display: flex;
overflow: auto;
position: relative;
border:1px solid;
}
.coursesSection--slider::after {
content: '';
background-image: linear-gradient(to right, transparent , #fff );
width: 5%;
margin-left:auto; /* push to the right */
flex-shrink:0;
position: sticky;
right: 0;
}
.courseCard:last-child {
margin-right:-5%; /* same as pseudo element width to create overlap */
}
.courseCard {
flex: 0 0 auto;
width: 100px;
height: 100px;
background-color: red;
margin-right: 10px;
}
<div class="coursesSection--slider">
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
</div>
TA贡献1871条经验 获得超8个赞
尝试位置fixed而不是最后一张牌的absolute和z-index
.coursesSection--slider {
display: flex;
overflow: auto;
position: relative;
}
.coursesSection--slider::after {
content: '';
background-image: linear-gradient(to right, transparent 0%, #fff 100%);
width: 40px;
height: 100px;
position: fixed;
right: 0;
top: 0;
}
.courseCard {
flex: 0 0 auto;
width: 100px;
height: 100px;
background-color: red;
margin-right: 10px;
}
.courseCard:last-child {
z-index: 2;
}
<div class="coursesSection--slider">
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
<div class="courseCard"></div>
</div>
- 2 回答
- 0 关注
- 115 浏览
添加回答
举报