gpt4 book ai didi

css - 需要一个 CSS 解决方案来保持页面滚动的左上角(不是位置 :fixed)

转载 作者:行者123 更新时间:2023-11-28 05:44:19 25 4
gpt4 key购买 nike

我需要打开/关闭一个总是出现在左上角的 div 容器,无论我在有页面滚动的页面上的什么位置。固定位置在桌面环境中是可以接受的,但在移动环境中,我需要用户能够向上或向下移动 div 容器,以便他们可以到达其他输入字段。如果我使用绝对位置,则当您在页面底部向下滚动时,div 容器可能会出现在 View 之外。

使用 fixed... 的示例问题移动设备弹出键盘将覆盖下方的输入字段。如果您将位置更改为绝对,那么您会看到视野之外的问题。 https://jsfiddle.net/r71vb73u/15/

 #workarea {
width: 160px;
padding: 5px;
height: 400px;
position: fixed;
background: #cccccc;
}

.input1 {
height: 90%;
}

.input2 {
height: 10%;
}

.blah {
float: left;
}

.buttons {
float: right;
}

.filler {
clear: both;
height: 800px;
}

function workarea(action) {
if (action == 'open') {
document.getElementById('workarea').style.display = '';
} else {
document.getElementById('workarea').style.display = 'none';
}
}

<body>
<div id="workarea">
<div class="input1">
<input type="text" value="hello">
</div>
<div class="input2">
<input type="text" value="world">
</div>
</div>
<div class="blah">blah blah ...</div>
<div class="buttons">
<input type="button" value="Open" onMouseDown="workarea('open');">
<input type="button" value="Close" onMouseDown="workarea('close');">
</div>
<div class="filler"></div>
<div class="blah">blah blah ...</div>
<div class="buttons">
<input type="button" value="Open" onMouseDown="workarea('open');">
<input type="button" value="Close" onMouseDown="workarea('close');">
</div>
</body>

最佳答案

好吧,这不是我的最终答案,但当你在移动环境中提到时,我一片空白。但首先我让你看到我的第一个答案。我会保持更新,直到你说这是一个正确的答案。查看DEMO

#workarea {
width: 160px;
padding: 5px;
position: fixed;
background: #cccccc;
left:0;
top:0;
bottom:0;
}

DEMO

关于css - 需要一个 CSS 解决方案来保持页面滚动的左上角(不是位置 :fixed),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37692757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com