【问题标题】:Scroll doesn't show the whole list of items滚动不显示整个项目列表
【发布时间】:2019-10-12 00:26:47
【问题描述】:

我有一个固定width 和height 的组件。我需要显示其中的项目列表。我使用了overflow: scroll;,但它没有显示整个列表!例如,如果我有 10 个项目,它不会显示项目 1,2 并且可能是 3 的一半! 我尝试了我在网上找到的所有东西,例如添加padding,height,或将其更改为overflow: auto;,但都没有成功!

SCSS:

.cart-dropdown {
  width: 300px;
  height: 400px;
  background-color: aqua;
  position: absolute;
  top: 60px;
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid black;
  z-index: 10;
  .cart-items {
    padding:10px;
    overflow: auto;
    width: 100%;
    height: 320px;
    margin: 5px;
    background-color: cornflowerblue;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }
  .button {
    margin: auto;
  }
}

组件:

const cartDropdown = ({cartItems}) => {
  const renderCartItem = cartItems => {
    return cartItems.map(item => <CartItem key={item.imageUrl} item={item} />);
  };

  return (
    <div className="cart-dropdown">
      <div className="cart-items">{renderCartItem(cartItems)}</div>
      <div className="button">
        <Button>GO TO CHECKOUT</Button>
      </div>
    </div>
  );
};

const mapStateToProps = ({ cartStatus: { cartItems } }) => ({
  cartItems
});

export default connect(mapStateToProps)(cartDropdown);

【问题讨论】:

  • 请添加代码示例以便我们查看
  • @TomEsposito 已编辑 :)
  • 一个小小的 js fiddle 就超级棒了
  • 你能提供一个完整的例子吗?你的html结构是什么?
  • @AmanSeth 完成 :)

标签: css reactjs sass


【解决方案1】:

好的,知道了,.cart-items 中的 flex-direction: column; 搞砸了滚动条!!我还不知道为什么,如果有人知道为什么滚动不显示所有列表,请在下面评论,谢谢:)

【讨论】:

  • 如果你在justify-content: flex-start;而不是.cart-items的中心,它还会发生吗?
  • @Pierre-Yves PERFECT :) 不,它不再发生了,谢谢,请以这种方式将其作为答案发布
  • 当时只是一个想法。认为 flex 居中可能会使内容溢出;)请参阅this post 以获得实际答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-22
  • 1970-01-01
  • 1970-01-01
  • 2019-07-13
  • 1970-01-01
  • 2014-01-14
  • 1970-01-01
相关资源
最近更新 更多