Configuring Basic Options
When you use Masonry.js to create Pinterest-style responsive grids, you control the layout by setting specific options during initialization. These options let you fine-tune how your grid items are arranged, how wide each column is, the spacing between columns, and how the grid fits within its container. Understanding these options is key to building a flexible and visually appealing layout.
The itemSelector option tells Masonry which elements inside your grid container should be treated as grid items. For example, if your grid items all have the class grid-item, you set itemSelector: '.grid-item'. This ensures only the intended elements are positioned by Masonry.
The columnWidth option sets the width of each column in your grid. This can be a fixed pixel value, a percentage, or a selector string pointing to an element whose width Masonry should use as the column width. By adjusting columnWidth, you control how many columns appear in the grid and how wide each one is.
The gutter option controls the horizontal space between columns. Increasing the gutter value adds more space between items, while a smaller value brings them closer together. This is especially useful for achieving a balanced look, preventing items from appearing too cramped or too spread out.
The fitWidth option, when set to true, makes the grid fit its container by aligning items in the center. This is helpful if you do not want the grid to stretch to fill the entire width of the container, but instead want it to be as wide as its columns plus gutters.
Let's see how these options come together in a simple Masonry.js setup.
index.html
style.css
script.js
Tack för dina kommentarer!
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Fantastiskt!
Completion betyg förbättrat till 8.33
Configuring Basic Options
Svep för att visa menyn
When you use Masonry.js to create Pinterest-style responsive grids, you control the layout by setting specific options during initialization. These options let you fine-tune how your grid items are arranged, how wide each column is, the spacing between columns, and how the grid fits within its container. Understanding these options is key to building a flexible and visually appealing layout.
The itemSelector option tells Masonry which elements inside your grid container should be treated as grid items. For example, if your grid items all have the class grid-item, you set itemSelector: '.grid-item'. This ensures only the intended elements are positioned by Masonry.
The columnWidth option sets the width of each column in your grid. This can be a fixed pixel value, a percentage, or a selector string pointing to an element whose width Masonry should use as the column width. By adjusting columnWidth, you control how many columns appear in the grid and how wide each one is.
The gutter option controls the horizontal space between columns. Increasing the gutter value adds more space between items, while a smaller value brings them closer together. This is especially useful for achieving a balanced look, preventing items from appearing too cramped or too spread out.
The fitWidth option, when set to true, makes the grid fit its container by aligning items in the center. This is helpful if you do not want the grid to stretch to fill the entire width of the container, but instead want it to be as wide as its columns plus gutters.
Let's see how these options come together in a simple Masonry.js setup.
index.html
style.css
script.js
Tack för dina kommentarer!