I try to make i image gallery. But I have a problem. When the size of the images are different, the image can not be beautiful. so i need to add resize pictures.e.g.. The dimensions of the photo width: 800px height: 400px another photo's size 600px 1024px. I want to see my pictures size in a div width: 198px height: 198px. if 100% of the width 198px height dimensions are very different.
I want like facebook, whatever the size of uploaded photos. Picture without image size width: 198px height: 198px get. This is my demo : CodePen
HTML :
<div class="profile_cover_container">
<div class="cover_container">
<div class="cover_img">
<a href="#"><div class="img_200px200px"><img src="https://scontent-b-fra.xx.fbcdn.net/hphotos-frc1/t1.0-9/1780641_780166082011699_1924260798_n.jpg" width="198" height="198" padding="0"></a></div>
<a href="#"><div class="img_200px200px"><img src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-prn2/t31.0-8/964870_679724332055875_989825665_o.jpg" width="198" height="auto" padding="0"></a></div>
</div>
</div>
</div>
CSS :
.profile_cover_container{
position:relative;
width:851px;
height:400px;
margin-left:auto;
margin-right:auto;
overflow:hidden;
border:1px solid #d8dbdf;
-webkit-border-bottom-right-radius: 3px;
-webkit-border-bottom-left-radius: 3px;
-moz-border-radius-bottomright: 3px;
-moz-border-radius-bottomleft: 3px;
border-bottom-right-radius: 3px;
border-bottom-left-radius: 3px;
margin-top:3px;
}
.cover_container {
width:851px;
height:400px;
float:left;
}
.cover_img {
float:left;
width:200px;
height:400px;
background-color:#000;
}
.img_200px200px {
float:left;
width:198px;
height:198px;
margin:1px;
overflow: hidden;
}
.img_200px200px img {
width: 100%;
}
I don't think you can do what you want with pure css as you will need to make a calculation to see if the images height is less than the width. As you have tagged this with jQuery, you can add the following css:
Then you can use this jQuery on document load
Example