html - 固定 Div 在整个屏幕上的拉伸(stretch),需要每个占据水平空间的百分比

标签 html css position fixed

我有 3 个主 div,它们应该水平分割屏幕(屏幕宽度的 45%、10% 和 45%)。最左边的 div(blue) 包含许多需要保持静态的较小的 div(aqua)。中间(绿色)和最右边(红色)的 div 应该在用户滚动时向下 float 页面,但应该保持在水平位置。我为所有的 div 设置了固定的高度,因为它们将保持一定的垂直尺寸。

我尝试为绿色和红色 div 分配固定位置,但它们移出位置并挡住了蓝色 div。

CSS

.PNMLB {
height: 400px;
font-style:italic;
overflow-y:scroll;
background-color:aqua;
border-style:double;}

HTML

<div class="MatchingDiv" style="width:100%">
            <div class="PNMListBoxes" style="width:45%; float:left;background-color:blue;">
                Left-most Div
                <!--generate programmatically?-->
                <div class="PNMLB" id="rank1">Rank 1<br/></div>
                <br/>
                <div class="PNMLB" id="rank2">Rank 2<br/></div>
                <br/>
                <div class="PNMLB" id="rank3">Rank 3<br/></div>
                <br/>
                <div class="PNMLB" id="rank4">Rank 4<br/></div>
                <br/>
            </div>
            <div class="Middle Div" style="width:10%;height:50px;float:left; background-color:lime;">Center Div</div>
            <div class="right div" style="overflow-y:scroll;height:400px;width:45%;float:right; background-color:red;">Right-most Div</div>

最佳答案

请为最右边的 div 使用样式 position:fixed;right:0%; ,为中心 div 使用 position:fixed;right:45%;

工作代码片段如下:

<style>.PNMLB {
height: 400px;
font-style:italic;
overflow-y:scroll;
background-color:aqua;
border-style:double;}
</style>

<div class="MatchingDiv" style="width:100%">
            <div class="PNMListBoxes" style="width:45%; float:left;background-color:blue;">
                Left-most Div
                <!--generate programmatically?-->
                <div class="PNMLB" id="rank1">Rank 1<br/></div>
                <br/>
                <div class="PNMLB" id="rank2">Rank 2<br/></div>
                <br/>
                <div class="PNMLB" id="rank3">Rank 3<br/></div>
                <br/>
                <div class="PNMLB" id="rank4">Rank 4<br/></div>
                <br/>
            </div>
            <div class="Middle Div" style="width:10%;height:50px;float:left; background-color:lime;position:fixed;right:45%;">Center Div</div>
            <div class="right div" style="overflow-y:scroll;height:400px;width:45%;float:right; background-color:red;position:fixed;right:0%">Right-most Div</div>

关于html - 固定 Div 在整个屏幕上的拉伸(stretch),需要每个占据水平空间的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51073488/

相关文章:

javascript - 从弹出窗口在父窗口中提交表单?

javascript - 页面加载期间显示菜单栏

css问题,外部div无法获取内部div的高度

html - 对齐图片,使其不在导航列表下换行。

iphone - 如何测试一个点是否在 View 中

javascript - jQuery 无法访问追加元素

html - Windows 7 以不同于 XP 或 Vista 的方式呈现网页

css - 使用 HTML 和 CSS 调整 DOM 元素的大小

html - 将 div 定位在 “absolute” <div> 的底部

regex - Postgres : Extract the last substring in a string