everybody!
I'm working on my personal website - an on-line portfolio. This is the first website I'm writing from scratch, so I'm new to HTML, CSS, JavaScript and PHP. In fact my knowledge of JavaScript and PHP is basic, so I'm using ready-to-use solutions. One of the solutions I use is Mansonry grid layout library, but unfortunately it doesn't work as I want it to. The problem is, when I open the webpage for the first time, all images collapse. When I renew the page, the images are aligned properly. I am wondering, how to fix it?
I'm using Masonry for the layout of project pages (http://vprilenska.netai.net/design_rigams.php). I want the library items to be aligned in four rows. Each library item is a div with an image and text. Divs are floated to the right.
<div class="item img">
<a href="image1.jpg">
<img src="image1.jpg"/>
<p>caption</p>
</a>
</div>
All images are of different height. Image width depends on column width. Column width and gutter are sized with elements, which, in turn, are set in percents of browser window width.
CSS for image size:
.item img {
max-width: 100%;
height: auto;
}
HTML and CSS for column width and gutter sizing elements:
<div class="col_width"></div>
<div class="gut_width"></div>
.col_width, .item {
width: 22.5%;
}
.gut_width {
width: 2%;
}
Masonry script, located between the closing body and html tags:
<script src='masonry.js'></script>
<script>
var container = document.querySelector('#masonry');
var masonry = new Masonry(container, {
gutter: container.querySelector('.gut_width'),
itemSelector: '.item',
columnWidth: container.querySelector('.col_width')
});
</script>
I think the problem is in the fact, that image height is not fixed. But maybe it's the fault of the total webpage layout.