【发布时间】:2019-08-25 10:30:54
【问题描述】:
如何将屏幕分成两半和左侧是图像固定的(如果您滚动导航栏,它们仍然在左侧且不可滚动)
我正在使用 flexbox 将屏幕分成两半,但有问题。
图像是可滚动的,而不是页面(屏幕)的全高。
我的 CSS:
.fo-container {
display: flex;
height: 100%;
justify-content: space-between;
}
.left-half {
/* The image used */
background-image: url("http://getwallpapers.com/wallpaper/full/9/9/0/722477-best-barber-wallpapers-1920x1080-samsung-galaxy.jpg");
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
flex: 1;
}
.right-half {
background-color: white;
flex: 1;
align-items: center;
padding: 1rem;
}
我的 HTML:
<div class="fo-container">
<div class="left-half"></div>
<div class="right-half"></div>
</div>
【问题讨论】:
-
将代码改为: 并在css中:.left-half,右半{高度:100vh;宽度:50vw; } .left-half{ 位置:固定; }