Masonry grid gets taller after I insert a new grid item









up vote
0
down vote

favorite












I'm trying to create a very basic grid layout with Masonry.js here. Basically I want to dynamically add a new grid item to my grid. This works normally except for one weird issue I see no matter how I try and implement this. When I add the new element, the item that was first in the list and all the way to the left moves to the far right side of the grid, and a space appears between the first and second items.



Before appending anything my grid looks like this



enter image description here



With this structure for html



 <div id="session-holder">
<div class="grid">
<div id="add-session" class="grid-item"><img src="Icons/add-orange.png"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>


JS



var element = document.querySelector(".grid")
var layout = new Masonry(element,
itemSelector : ".grid-item",
fitWidth: true,
)


CSS



#session-holder
height: fit-content;

.grid
width: 540px;

#add-session
border-width: 3px;
box-sizing: border-box;
border-style: solid;
border-color: #ff7c4d;
color: white;
display: flex;
justify-content: center;
align-items: center;
background-color: transparent;
transition: opacity 1s linear;

#add-session:hover
opacity: .7;

#add-session:hover > img
transform: rotateZ(90deg);

#add-session > img
transition: transform .2s linear;
height: 50px;
width: 50px;

#next-session
background-color: transparent;
border-color: orangered;
border-width: 2px;
border-style: solid;
box-sizing: border-box;

.grid-item
background-color: #333333;
border-radius: 2px;
height: 130px;
width: 160px;
margin: 5px;



After adding the item the grid looks like this...



enter image description here



As expected the new grid item fills in the last spot, but now I also have this giant gap at the top to deal with. The space that's inserted at the top appears to be the same height as one row of grid-items (probably not a coincidence).



I could just use css grids to achieve the same appearance, but I like that Masonry grid-items are animated (which is something I really don't want to try and reproduce).



I've looked around in Masonry's documentation for a solution or possible explanation but haven't found a smoking pistol.



Any ideas?










share|improve this question





















  • Can you make a Minimal, Complete, and Verifiable example as I cannot reproduce this with your current code, working exanple: jsfiddle.net/bqmnkewo
    – Patrick Evans
    Nov 12 at 2:51











  • Thats interesting. I see you're example is working normally. Before I do anything else let me compare your example with my code to see if I can get it working normally.
    – Carl
    Nov 12 at 2:58










  • using the code you have there does work. I'm not sure why but something I'm doing in mine is creating that extra space. I'll take a closer look at my code and see if I can't figure it out. Thanks!
    – Carl
    Nov 12 at 3:03














up vote
0
down vote

favorite












I'm trying to create a very basic grid layout with Masonry.js here. Basically I want to dynamically add a new grid item to my grid. This works normally except for one weird issue I see no matter how I try and implement this. When I add the new element, the item that was first in the list and all the way to the left moves to the far right side of the grid, and a space appears between the first and second items.



Before appending anything my grid looks like this



enter image description here



With this structure for html



 <div id="session-holder">
<div class="grid">
<div id="add-session" class="grid-item"><img src="Icons/add-orange.png"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>


JS



var element = document.querySelector(".grid")
var layout = new Masonry(element,
itemSelector : ".grid-item",
fitWidth: true,
)


CSS



#session-holder
height: fit-content;

.grid
width: 540px;

#add-session
border-width: 3px;
box-sizing: border-box;
border-style: solid;
border-color: #ff7c4d;
color: white;
display: flex;
justify-content: center;
align-items: center;
background-color: transparent;
transition: opacity 1s linear;

#add-session:hover
opacity: .7;

#add-session:hover > img
transform: rotateZ(90deg);

#add-session > img
transition: transform .2s linear;
height: 50px;
width: 50px;

#next-session
background-color: transparent;
border-color: orangered;
border-width: 2px;
border-style: solid;
box-sizing: border-box;

.grid-item
background-color: #333333;
border-radius: 2px;
height: 130px;
width: 160px;
margin: 5px;



After adding the item the grid looks like this...



enter image description here



As expected the new grid item fills in the last spot, but now I also have this giant gap at the top to deal with. The space that's inserted at the top appears to be the same height as one row of grid-items (probably not a coincidence).



I could just use css grids to achieve the same appearance, but I like that Masonry grid-items are animated (which is something I really don't want to try and reproduce).



I've looked around in Masonry's documentation for a solution or possible explanation but haven't found a smoking pistol.



Any ideas?










share|improve this question





















  • Can you make a Minimal, Complete, and Verifiable example as I cannot reproduce this with your current code, working exanple: jsfiddle.net/bqmnkewo
    – Patrick Evans
    Nov 12 at 2:51











  • Thats interesting. I see you're example is working normally. Before I do anything else let me compare your example with my code to see if I can get it working normally.
    – Carl
    Nov 12 at 2:58










  • using the code you have there does work. I'm not sure why but something I'm doing in mine is creating that extra space. I'll take a closer look at my code and see if I can't figure it out. Thanks!
    – Carl
    Nov 12 at 3:03












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to create a very basic grid layout with Masonry.js here. Basically I want to dynamically add a new grid item to my grid. This works normally except for one weird issue I see no matter how I try and implement this. When I add the new element, the item that was first in the list and all the way to the left moves to the far right side of the grid, and a space appears between the first and second items.



Before appending anything my grid looks like this



enter image description here



With this structure for html



 <div id="session-holder">
<div class="grid">
<div id="add-session" class="grid-item"><img src="Icons/add-orange.png"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>


JS



var element = document.querySelector(".grid")
var layout = new Masonry(element,
itemSelector : ".grid-item",
fitWidth: true,
)


CSS



#session-holder
height: fit-content;

.grid
width: 540px;

#add-session
border-width: 3px;
box-sizing: border-box;
border-style: solid;
border-color: #ff7c4d;
color: white;
display: flex;
justify-content: center;
align-items: center;
background-color: transparent;
transition: opacity 1s linear;

#add-session:hover
opacity: .7;

#add-session:hover > img
transform: rotateZ(90deg);

#add-session > img
transition: transform .2s linear;
height: 50px;
width: 50px;

#next-session
background-color: transparent;
border-color: orangered;
border-width: 2px;
border-style: solid;
box-sizing: border-box;

.grid-item
background-color: #333333;
border-radius: 2px;
height: 130px;
width: 160px;
margin: 5px;



After adding the item the grid looks like this...



enter image description here



As expected the new grid item fills in the last spot, but now I also have this giant gap at the top to deal with. The space that's inserted at the top appears to be the same height as one row of grid-items (probably not a coincidence).



I could just use css grids to achieve the same appearance, but I like that Masonry grid-items are animated (which is something I really don't want to try and reproduce).



I've looked around in Masonry's documentation for a solution or possible explanation but haven't found a smoking pistol.



Any ideas?










share|improve this question













I'm trying to create a very basic grid layout with Masonry.js here. Basically I want to dynamically add a new grid item to my grid. This works normally except for one weird issue I see no matter how I try and implement this. When I add the new element, the item that was first in the list and all the way to the left moves to the far right side of the grid, and a space appears between the first and second items.



Before appending anything my grid looks like this



enter image description here



With this structure for html



 <div id="session-holder">
<div class="grid">
<div id="add-session" class="grid-item"><img src="Icons/add-orange.png"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>


JS



var element = document.querySelector(".grid")
var layout = new Masonry(element,
itemSelector : ".grid-item",
fitWidth: true,
)


CSS



#session-holder
height: fit-content;

.grid
width: 540px;

#add-session
border-width: 3px;
box-sizing: border-box;
border-style: solid;
border-color: #ff7c4d;
color: white;
display: flex;
justify-content: center;
align-items: center;
background-color: transparent;
transition: opacity 1s linear;

#add-session:hover
opacity: .7;

#add-session:hover > img
transform: rotateZ(90deg);

#add-session > img
transition: transform .2s linear;
height: 50px;
width: 50px;

#next-session
background-color: transparent;
border-color: orangered;
border-width: 2px;
border-style: solid;
box-sizing: border-box;

.grid-item
background-color: #333333;
border-radius: 2px;
height: 130px;
width: 160px;
margin: 5px;



After adding the item the grid looks like this...



enter image description here



As expected the new grid item fills in the last spot, but now I also have this giant gap at the top to deal with. The space that's inserted at the top appears to be the same height as one row of grid-items (probably not a coincidence).



I could just use css grids to achieve the same appearance, but I like that Masonry grid-items are animated (which is something I really don't want to try and reproduce).



I've looked around in Masonry's documentation for a solution or possible explanation but haven't found a smoking pistol.



Any ideas?







javascript css masonry






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 1:58









Carl

337




337











  • Can you make a Minimal, Complete, and Verifiable example as I cannot reproduce this with your current code, working exanple: jsfiddle.net/bqmnkewo
    – Patrick Evans
    Nov 12 at 2:51











  • Thats interesting. I see you're example is working normally. Before I do anything else let me compare your example with my code to see if I can get it working normally.
    – Carl
    Nov 12 at 2:58










  • using the code you have there does work. I'm not sure why but something I'm doing in mine is creating that extra space. I'll take a closer look at my code and see if I can't figure it out. Thanks!
    – Carl
    Nov 12 at 3:03
















  • Can you make a Minimal, Complete, and Verifiable example as I cannot reproduce this with your current code, working exanple: jsfiddle.net/bqmnkewo
    – Patrick Evans
    Nov 12 at 2:51











  • Thats interesting. I see you're example is working normally. Before I do anything else let me compare your example with my code to see if I can get it working normally.
    – Carl
    Nov 12 at 2:58










  • using the code you have there does work. I'm not sure why but something I'm doing in mine is creating that extra space. I'll take a closer look at my code and see if I can't figure it out. Thanks!
    – Carl
    Nov 12 at 3:03















Can you make a Minimal, Complete, and Verifiable example as I cannot reproduce this with your current code, working exanple: jsfiddle.net/bqmnkewo
– Patrick Evans
Nov 12 at 2:51





Can you make a Minimal, Complete, and Verifiable example as I cannot reproduce this with your current code, working exanple: jsfiddle.net/bqmnkewo
– Patrick Evans
Nov 12 at 2:51













Thats interesting. I see you're example is working normally. Before I do anything else let me compare your example with my code to see if I can get it working normally.
– Carl
Nov 12 at 2:58




Thats interesting. I see you're example is working normally. Before I do anything else let me compare your example with my code to see if I can get it working normally.
– Carl
Nov 12 at 2:58












using the code you have there does work. I'm not sure why but something I'm doing in mine is creating that extra space. I'll take a closer look at my code and see if I can't figure it out. Thanks!
– Carl
Nov 12 at 3:03




using the code you have there does work. I'm not sure why but something I'm doing in mine is creating that extra space. I'll take a closer look at my code and see if I can't figure it out. Thanks!
– Carl
Nov 12 at 3:03

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255112%2fmasonry-grid-gets-taller-after-i-insert-a-new-grid-item%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255112%2fmasonry-grid-gets-taller-after-i-insert-a-new-grid-item%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto