javascript - How can I make the image smaller width? Masonry -
basically not know how change width of image looks in design.
i'm new working library , want know how can change example in design.
the middle image smaller other two. preserved , height three
i have sample
code html:
<div class="grid"> <div class="grid-sizer"></div> <div class="grid-item item-1"> <img src="http://bagelhousecafe.ch/wp-content/themes/wp_bagel/assets/img/img-01.png" /> </div> <div class="grid-item item-2"> <img src="http://bagelhousecafe.ch/wp-content/themes/wp_bagel/assets/img/img-02.png" /> </div> <div class="grid-item item-3"> <img src="http://bagelhousecafe.ch/wp-content/themes/wp_bagel/assets/img/img-03.png" /> </div> </div>
code css:
* { box-sizing: border-box; } /* force scrollbar */ html { overflow-y: scroll; } body { font-family: sans-serif; } /* ---- grid ---- */ .item-1,.item-3{ width:40%; } .grid { background: #ddd; } /* clear fix */ .grid:after { content: ''; display: block; clear: both; } /* ---- .grid-item ---- */ .grid-sizer, .grid-item { width: 33.333%; } .grid-item { float: left; } .grid-item img { display: block; width: 100%; }
code js:
// external js: masonry.pkgd.js, imagesloaded.pkgd.js // init masonry after images have loaded var $grid = $('.grid').imagesloaded( function() { $grid.masonry({ itemselector: '.grid-item', percentposition: true, columnwidth: '.grid-sizer' }); });
thanks in advance!
minor change in these css declaration fix issue
.grid-item { width: 33.333%; height: 200px; // added height } .grid-item {} // no need of float left .grid-item img { min-width: 100%; //defined max-height,max-width & min-height max-width: 100%; max-height: 100%; }
check codepen
Comments
Post a Comment