Line break with different image height, Bootstrap

Asked

Viewed 139 times

1

I have a problem in my Grid with line breaking, the images come from a database and are of different heights, some horizontal and other vertical.

I’m wearing the bootstrap.

I have that code

<div class="row">
<div class="col-sm-4 borda_cat">

<a href="produtos/<?php echo $row_categoria2["url"] ?>/<?php echo $row_subcategoria2["url"] ?>/<?php echo $row_produtos["url"] ?>" class="hvr-bubble-top"><img src="uploads/<?php echo $row_fotos_produtos["nome"]?>" class="img-responsive"></a>  

</div>                    
</div>

on the website the images look like this

inserir a descrição da imagem aqui

How would you align the columns being that the heights are different?

1 answer

0

You can do thumbnails. You can do "manually" by cutting the images and saving the Thumbs, or you can do "virtual" that would be at runtime, an excellent library to do this is the Smartcrop.

jQuery(document).ready(function($){
    $('.borda_cat').each(function(i, el){
    crop($('img.img-responsive', el).get(0), $(el).width());
  });
});

function crop(image, size) {
  console.log('crop',image);
  var options = {debug: false, width: size, height: size};
  var _img = new Image;

  _img.crossOrigin = 'Anonymous';
  _img.onload = function() {
    window.setTimeout(function() {
      var img = this;
      console.log('start crop');
      smartcrop.crop(img, options, function(result) {

        var crop = result.topCrop;
        var canvas = $('<canvas />')[0];
        var ctx = canvas.getContext('2d');
        canvas.width = options.width;
        canvas.height = options.height;
        ctx.drawImage(img, crop.x, crop.y, crop.width, crop.height, 0, 0, canvas.width, canvas.height);

        $(image).hide().after(canvas);

        console.log('crop end');
      });
    }.bind(this), 100);
  };
  _img.src = image.src;
}
  • the images cannot be cropped, because the sizes are forward, would not have to do with css, jquery or bootstrap?

  • Another solution would be to standardize the size of the images, on the web there is no "magic", or you standardize before you put there, or you standardize there, you have to see what will give you less work and what best suits you. You can even join this with a lightbox to see the original image...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.