【发布时间】:2014-07-31 10:18:52
【问题描述】:
我目前正在开发一个聊天网站,在使用聊天显示时遇到了一个奇怪的问题。现在,我有一个div,我的 jQuery 会动态地向其中添加聊天行。我想让div 的高度为 100%,以便我可以根据用户的配置调整其大小,但是当我这样做时,div 会展开而不是滚动。
我做了很多研究,但没有运气。例如,我尝试在我的 CSS 中强制使用 overflow-y: scroll,将 max-height 设置为 100%,但仍然没有成功。然而,我注意到的有趣的事情是,这个问题似乎并没有在 Chrome 中发生,但在 Firefox 31.0 和 IE 11 中确实重现。
这是我的 HTML(修改为仅显示相关部分):
<html height="100%">
<link rel="stylesheet" href="./stylesheets/style.css"> <!-- Mainly background colors, etc -->
<link rel="stylesheet" href="./stylesheets/chat.css"> <!-- Most of this page's styling comes from here -->
<link rel="stylesheet" href="./stylesheets/buttons.css"> <!-- Reskining the bootstrap buttons -->
<script src="./javascripts/jquery/jquery-1.7.2.min.js"></script>
<script src="./javascripts/chat.js"></script> <!-- the js that facilitates chatting -->
<link rel="stylesheet" href="./dist/css/bootstrap.min.css">
<script src="./dist/js/bootstrap.min.js"></script>
<body style="background-color: #ccc;" height="100%" width="100%">
<div id="pageHeader" width="100%" height="20%">
...
</div>
<table width="100%" height="70%" style="margin: 0px">
<tr width="100%" height="70%">
<td width="60%" height="100%">
<div id="msgWindow" class="shadow"></div> <!-- The is is the div I'm referring to -->
</td>
<td width="25%" height="100%">
<div id="roomWindow" class="shadow" height="100%"></div>
</td>
<td width="15%" height="100%">
...
</td>
</tr>
<tr height="15%">
...
</tr>
</table>
<table height="10%" width="100%">
<tr height="95%" width="100%">
...
</tr>
<tr height="5%" width="100%">
<td><p style="color:grey">BETA 1.0</p></td>
</tr>
</table>
</body>
</html>
聊天.css:
#msgWindow {
position: relative;
background-color: #fff;
display: inline-block;
white-space: pre;
overflow-y: scroll;
width: 100%;
max-width: 100%;
height: auto;
max-height: 100%;
}
h1{
color: #3366BB;
}
#roomWindow {
background-color: #fff;
white-space: pre;
overflow-y: auto;
overflow-x: hidden;
width: 100%;
height: 100%;
}
.shadow {
box-shadow: 2px 2px 4px 1px #000000;
padding-top: 10px;
padding-right: 1px;
padding-bottom: 10px;
padding-left: 15px;
}
.allMsg {
max-width: 550px !important;
white-space: pre-wrap;
}
.userSpan {
font-size: 9pt;
background-color: #FFFFCC;
width: 100px;
max-width: 100px;
min-width: 100px;
}
我在动态添加聊天行时使用的 JS 是这样的:
var html = "<tr><td class='userSpan'>" + msg.source + "</td><td class='allMsg'>" + msg.message + "</td>";
$('#msgWindow').append(html);
style.css 不包含任何布局内容,仅包含颜色和字体。
我花了太长时间试图解决这个问题,所以我一定忽略了一些非常简单的事情。
提前致谢!
【问题讨论】:
标签: jquery html css cross-browser