首页 > 解决方案 > 如何将输入定位在屏幕底部?

问题描述

我需要在 a 中放置一个<input><div>以便当用户滚动时,该<input>位置相对于屏幕保持不变。我试过relativeand absolutewith position:,但既不保持相对于屏幕,也保持相对于页面大小。

.console {
  position: absolute;
  right: 0px;
  background-color: #fff;
  width: 300px;
  height: 600px;
  border: 1px solid black;
  overflow-y: auto;
}

.run {
  position: absolute;
  bottom: 0px;
  width: 295px;
}
<div class='console' height='600'>
    <input class='run' type='text' placeholder='I want this to be relative to the bottom of screen' />
</div>

该片段显示<input>停留在页面底部;我需要它位于用户屏幕的底部。最简单的方法是什么?

标签: javascriptjqueryhtmlcss

解决方案


我用过position: fixed;,效果很好。


推荐阅读