【发布时间】:2021-11-23 05:42:16
【问题描述】:
我有一个高度大于屏幕尺寸的侧边栏,当使用position: sticky 时,在滚动到页面末尾之前,我将无法看到侧边栏的底部。
如何确保在滚动时,例如 50% 的页面已经显示侧边栏的下部?
这里的代码示例:https://jsfiddle.net/zxypmqvg/3/
.main-block {
display: flex;
}
.sidebar {
background-color: LightCoral;
width: 25%;
}
.sidebar-content {
margin: 5px;
margin-bottom: 40px;
background-color: LimeGreen;
position: sticky;
top: 0;
}
.main-content {
width: 75%;
height: 4000px;
background-color: LightBlue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="main-block">
<div class="sidebar">
<div class="sidebar-content">
<p>sometext for example for stackoverfrom</p>
<p>sometext for example for stackoverfrom</p>
<p>sometext for example for stackoverfrom</p>
<p>sometext for example for stackoverfrom</p>
<p>sometext for example for stackoverfrom</p>
<p>sometext for example for stackoverfrom</p>
<p>last string</p>
</div>
</div>
<div class="main-content">
</div>
</div>
</body>
</html>
最后一个字符串仅在达到页尾时显示
【问题讨论】:
标签: css css-position sticky