我使用HTML将小部件设置为粘性,但它并不像粘性那样工作。当滚动条向下时,小部件也会向下。我要创建的结构
Header
page sticky-page title
page-content/sticky widget
字符串
我不想以任何方式使用固定。
我想用图片展示我想做的事情。我很感激你的帮助
的数据
body {
margin: 0;
padding: 0;
}
.flex-container {
display: flex;
flex-direction: column;
height: 100vh;
}
.header {
background-color: #f39c12;
height: 60px;
overflow: hidden;
}
.content {
display: flex;
flex: 1;
overflow: auto;
}
.main-container {
max-width: 1000px;
margin: auto;
flex: 1;
display: flex;
flex-direction: column;
position: relative;
}
.sticky-element {
position: sticky;
top: 0;
background-color: #ecf0f1;
}
.sticky-widget {
position: sticky;
top: 0;
background-color: #3498db;
color: #fff;
padding: 10px;
}
.main-content {
display: flex;
flex-direction: row;
}
.column {
flex: 1;
padding: 20px;
}
.footer {
background-color: #2ecc71;
height: 40px;
}
<div class="flex-container">
<!-- Header -->
<div class="header">Header</div>
<!-- Content -->
<div class="content">
<div class="main-container">
<!-- Sticky Element -->
<div class="sticky-element">page STİCK TİTLE</div>
<!-- Main Content -->
<div class="main-content">
<div class="column">
<!-- Content on the left side -->
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor augue vel mi congue, vel pharetra arcu bi
</div>
<div class="column sticky-widget">
<!-- Example content -->
<div>WİDGET</div>
</div>
</div>
</div>
</div>
<div class="footer">Footer</div>
</div>
的数据
1条答案
按热度按时间tf7tbtn21#
解决办法!只要给予
字符串
在
.sticky-widget
类中。代码如下:
的数据
请随意提出任何疑问!