【问题标题】:Filling height of page with position absolute绝对位置的页面填充高度
【发布时间】:2021-04-05 22:52:58
【问题描述】:

即使页面有滚动条并且我滚动到底部,我如何定位 div 以占据页面高度的 100%。我的 div 是模态的,位于导航栏下方,我将最小高度设置为 100vh,但是当我向下滚动时,它似乎没有扩展到页面底部。我使用的绝对位置不是固定的,因为我希望它相对于导航栏。

    <header className ={styles.header}>
    <span className={styles.header__item} onClick={() => handleTab(1)}>Library</span>
    <div className={styles.img} onClick={()=>handleOptions()}>                   
    </div>  
    <input className={styles.search} type ="text" placeholder="Search"></input> 
    <PlayerModal open={playerOpen}/>
    </header> 


.modalStyles{
    min-height: 100vh;
    width: 26vw;
    position: absolute;
    left: 74%;
    top: 100%;
    background-color: whitesmoke;
}

【问题讨论】:

  • 100vh 表示 100% 的视图高度,即所有页面的整体可见部分(可以是移动端全屏的桌面窗口)

标签: html css reactjs


【解决方案1】:

您可以使用位置粘性而不是绝对位置并将其设置在导航的底部。

#sticky {
  position: sticky;
  position: -webkit-sticky;
  background: #f83d23;
  width: 100px;
  height: 100px;
  top: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 6px #000;
  color: #fff;
}
.extra,
#wrapper {
  width: 75%;
  margin: auto;
  background-color: #ccc;
}
#wrapper {
  height: 800px;
}
.extra {
  height: 100px;
}
body {
  font-family: georgia;
  height: 1000px;
}
h4 {
  text-align: center;
}
@media (min-height: 768px) {
  #wrapper{
    height: 2000px;
  }
}
<h4>Scroll to see the sticky element <em>sticking</em></h4>

<div id="wrapper">
  <div id="sticky">
    sticky
  </div>
</div>
<br />
<div class="extra"></div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 2011-09-27
    • 2017-04-15
    • 1970-01-01
    • 2015-07-24
    • 2011-06-21
    • 2013-01-05
    相关资源
    最近更新 更多