1

I am using react masonry library: https://www.npmjs.com/package/react-masonry-component I have added three items with different width/height: image

import React from 'react';
import Masonry from 'react-masonry-component';

const gridItems = [
    { width:"200px",height: "200px"},
    { width:"100px",height: "100px"},
    { width:"100px",height: "100px"}
].map((i, index) => {

    return <div className={`grid-item`} style={{width: i.width, height: i.height}}>
        <div style={{backgroundColor: 'green', height: '100%'}}>{index}</div>
    </div>;
})

const gridView = (props) => {

    return <div className="">
        <Masonry
            className={'masonry-view'}
           >
            {gridItems}
        </Masonry>
    </div>;
}

export default gridView;

Issue is visible on attached image - third item is not aligned correctly. Does anyone know solution?

2 Answers2

0

SOLUTION: Problem was that I had not added columnsWidth property. So I created Options object and added columnsWidth to smallest column width and it worked.

0

To fix this issue I just fix the columnWidth to 1.

<Masonry
  options={{
     columnWidth: 1,
  }}
>
....
</Masonry>
Maxime
  • 643
  • 10
  • 21