简体   繁体   English

overflow-y:滚动或自动无法按预期工作。 它没有滚动

[英]overflow-y: scroll or auto not working as intended. It is not scrolling

I am using vue.js with less.我使用的是 vue.js 和 less。 I am trying to scroll a div with overflow but its is not working it stays like overflow:hidden我正在尝试滚动带有溢出的 div 但它不起作用它保持像溢出:隐藏

Screenshot of the problem.问题截图。

This is the code这是代码

<template>
  <div class="chatarea" v-if="currentRoom">
    <ChatInput />
    <div class="chatbox">
      <ChatBit
        :message="chats.message"
        :sender="chats.username"
        v-for="(chats, index) in messages[currentRoom]"
        :key="index"
      />
    </div>
  </div>
</template>

This is the css这是css

<style lang="less" scoped>
.chatarea {
  width: calc(100% - 300px);
  height: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  background-color: #3b3d47 - #222222;
  .chatbox {
    height: calc(100% - 50px);
    // height: 600px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow-y: scroll;
  }
}
</style>

Thanks for any help:)谢谢你的帮助:)

in this case you have commented the line that you set a height to the element that you want it to scroll, just replace this block of code: height: 600px; // You had commented this line在这种情况下,您已经注释了为要滚动的元素设置高度的行,只需替换此代码块: height: 600px; // You had commented this line height: 600px; // You had commented this line

and it's better to set overflow to auto , therfore if the chat does't scroll (height of chats is less that height of container) the scroll bar not show and it does't make your UI bad.并且最好将overflow设置为auto ,因此如果聊天不滚动(聊天的高度小于容器的高度)滚动条不显示并且它不会使您的 UI 变坏。

Whenever I use the css overflow-y attribute, I would normaly use the value auto instead of scroll .每当我使用 css overflow-y属性时,我通常会使用值auto而不是scroll

Here is your css that I changed, and now it should work for you.这是我更改的 css,现在它应该对你有用了。 VueJS isn't the problem here. VueJS 不是这里的问题。

<style lang="less" scoped>
.chatarea {
  width: calc(100% - 300px);
  height: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  background-color: #3b3d47 - #222222;
  .chatbox {
    height: calc(100% - 50px);
    // height: 600px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow-y: auto;
  }
}
</style>

Try giving max-height attribute尝试提供 max-height 属性

.chatarea {
  width: calc(100% - 300px); 
  height: 100%; // suggest you to 100vh
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  background-color: #3b3d47 - #222222;
  .chatbox {
    max-height: calc(100% - 50px);
    // height: 600px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow-y: scroll;
  }
}

Thanks for everyone who helped.感谢所有帮助过的人。 The problem was in justify-content:flex-end I removed the line and everything started to work as intended.问题出在justify-content:flex-end我删除了该行,一切都开始按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM