【问题标题】:react-masonry-component not centered in the parent divreact-masonry-component 不在父 div 中居中
【发布时间】:2021-08-10 15:30:00
【问题描述】:

我正在使用 npm react-masonry-component 为我的页面创建一个类似砖石的网格。我不知道如何让网格在父元素中居中。

我在代码框here上设置了一个演示版

【问题讨论】:

标签: html css reactjs npm


【解决方案1】:

只需将isFitWidth: true 设置为您传递给砌体组件的选项,如您所见in this forked codepen

  const masonryOptions = {
    transitionDuration: 0,
    fitWidth: true // <-- this option will do the job
  };

  return (
    <section id="artists">
      <Masonry
        options={masonryOptions}
        className={"my-gallery-class masonry"}
        elementType={"ul"}
        disableImagesLoaded={false}
        updateOnEachImageLoad={false}
      >

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-29
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多