在过去的几个小时里,我一直在为这个问题绞尽脑汁。我正在尝试制作一个保留在页面底部的输入字段,类似于 Omegle 聊天栏。
我已将高度设置为 100%(好吧,99,因为如果设置为 100,页面就会有不必要的滚动条)并将 CSS bottom
属性设置为 0
,但无论我尝试什么,该栏都在页面下方 10% 左右浮动。
我的 CSS 代码是:
html {
height:99%;
width:99%;
}
input.chatbar {
bottom:0;
width:90%;
height:5%;
outline:none;
resize: none;
border:none;
border-bottom:#000 medium solid !important;
}
我的 HTML 代码是
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Global Chat</title>
</head>
<body>
<input class="chatbar" />
</body>
</html>
和here是它的一个 JSFiddle。
我希望它 float 在页面上方并随用户滚动,就像聊天栏一样。我该怎么做?
抱歉,我知道这是一个基本问题,但我在其他地方找不到答案。
最佳答案
添加 position: fixed;
到 css
还要注意百分比高度。查看min and max height properties
关于html - 将输入固定到页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15081196/