【问题标题】:Can't get vertical scrollbar with justify-content: flex-end无法使用 justify-content: flex-end 获得垂直滚动条
【发布时间】:2017-06-11 07:24:36
【问题描述】:

每当我使用justify-content: flex-end; 时,我都会遇到滚动条问题。我禁用了滚动条如何解决。希望有人可以帮助我。

重建

$(".input").on("keydown", function(e) {
  if (e.keyCode === 13) {
    $(".text").append($("<p />", {
      html: $(".input").val()
    }))
    e.preventDefault()
    $(".input").val("")
  }
})

// AUTO INPUT

for (var i = 0; i < 10; i++) {
  $(".text").append($("<p />", {
    html: "test"
  }))
}
$(".text").append($("<p />", {
  html: "Now we see that the scrollbar works, its now gonna add <b>justify-content: flex-end;</b> than you see the scrollbar disables it self in 6 seconds"
}))

$(".text").scrollTop($(".text")[0].scrollHeight);

setTimeout(function() {
  $(".text").css("justify-content", "flex-end");
  $(".text").append($("<h3 />", {
    html: "justify-content: flex-end; is added and scrollbar is disabled"
  }))

  $(".text").scrollTop($(".text")[0].scrollHeight);
}, 6000)
.text {
  height: 10em;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
p {
  margin: 0
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">
  <div class="text">
  </div>
</div>
<input type="text" class="input">

【问题讨论】:

    标签: javascript html css flexbox


    【解决方案1】:

    同样的原因,当某些东西溢出到body 的左侧或顶部时,您无法滚动到左侧或“向上”来查看溢出。您开始滚动查看body 的点从顶部/左侧body 开始。就像这个 div 的滚动点从 div 的开头/顶部开始一样。您不能滚动到 div 中的负数位置,就像您不能滚动到 body 中的负数位置一样。

    div {
      background: red;
      height: 100px;
      width: 100px;
      position: absolute;
    }
    .left {
      top: 0;
      left: -50px;
    }
    .right {
      top: 0;
      right: -50px;
    }
    .top {
      top: -50px;
      left: 50%;
    }
    .bottom {
      bottom: -50px;
      left: 50%;
    }
    <div class="left"></div>
    <div class="right"></div>
    <div class="top"></div>
    <div class="bottom"></div>

    【讨论】:

    • 那么我的例子没有修复吗?
    【解决方案2】:

    这似乎是一个错误。

    有一些变通方法,但它们在浏览器中可能很笨拙且不可靠。

    例如,在您的代码中,如果您颠倒 HTML 中内容的顺序,并将 flex-direction 切换为 column-reverse,您将获得滚动条...在 Chrome 中(没有'不适用于 FF 或 Edge)。

    jsFiddle demo

    以下是一些可能有用的参考资料:

    【讨论】:

    猜你喜欢
    • 2016-07-07
    • 2022-01-26
    • 1970-01-01
    • 2013-12-06
    • 2022-01-15
    • 2017-08-14
    • 2010-11-29
    • 2018-09-17
    • 2015-12-13
    相关资源
    最近更新 更多