html - 如何使消息在滚动前不拉伸(stretch)

标签 html css material-design

我们正在使用 Google 的 Material 创建一个 Messenger,如果您在网格中输入消息,第一条消息将填满整个区域,当添加第二条消息时,两条消息将占据页面的一半,这继续直到消息不能变小,直到它最终开始滚动。然后向下滚动的滚动自动化工作,但一开始看起来很愚蠢。

不太好看 not so good looking

这就是消息无法变小后的样子 This is what it looks like once the messages can't get smaller

 <div class="mdl-tabs__panel is-active chatbox" id="newest-panel">

       <section class="mdl-grid chatdiv">

          <div class=" chat mdl-cell mdl-cell--3-col mdl-cell--7-col-tablet mdl-cell--11-col-desktop">
            <div class="NameOfSender">Anton</div>
            <div class="ChatMessage">Inwiefern beeinflusst das autonome Fahren meinen Alltag?</div>
            <div class="Timestamp">- vor 3 min</div>
          </div>

    .chatbox{

  position: fixed;
  width: 100%;
  height: 81vh;  
  padding-bottom: 1px;
  overflow-y: scroll;
}

.chatdiv{

  position: fixed;
  width: 100%;
  height: 50vh;   
  overflow-y: scroll;
}

$("#messagefield").stop().animate({ scrollTop: $("#messagefield")[0].scrollHeight}, 1000);

我该如何解决这个问题? 重要说明:新消息是通过 javascript 动态添加的!

提前致谢!

最佳答案

您应该尝试在 .chatbox 上使用 max-height 属性

.chatbox {
  position: fixed;
  width: 100%;
  height: 81vh;
  max-height: /*whatever suits*/; /* <-- Here is the fix*/
  padding-bottom: 1px;
  overflow-y: scroll;
}

.chatdiv {
  position: fixed;
  width: 100%;
  height: 50vh;
  overflow-y: scroll;
}

关于html - 如何使消息在滚动前不拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47268658/

相关文章:

javascript - 水平固定列在 IE 上滞后

html - 元名称 ="viewport"和 @media : activate CSS based upon width of actual page

html - 如何让div展开

html - 这是什么意思 : data-component-bound ="true"?

android - 如何模糊 android 中的 View 或布局?

android - ImageView 覆盖覆盖按钮的波纹效果

JavaScript:替换网页上的(所有)某些单词

html - html5样板代表什么?

html - 垂直和水平对齐 Owl Carousel 箭头 slider 中的图像

javascript - 导航栏中的滚动在 Material Design Lite v1.0.5 中不起作用