-2

I am using simple css code for Profile Image Styling, but Image is stretched. How can i fix it?

Take a look at the Profile Images in this Picture:

enter image description here

Right Now I am Using this Code:

.Comment_Image_Size {
    height: 32px;
    width: 28px;
}

I also used this Code but in this case some Images are Bigger and some are smaller in height:

.Comment_Image_Size {
    width: 28px;
}
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Hassan Sardar
  • 4,413
  • 17
  • 56
  • 92

3 Answers3

2

Don't fix the image dimensions, I think the project you are working on should be dynamic, if it's yes, than you can also resize the images via server side, if you don't want to do that, and want to stick with HTML and CSS, than use a wrapping element, say div, float it to the left, assign some fix height & width and assign a class, and than use the below snippet to

div.class_name img {
   max-width: 100%;
   max-height: 100%;
}

This way, your image will resize proportionally and it won't be stretched anymore

Demo (I've attached both examples, you can check out in the demo)

In the above demo, the first one is which I've suggested to you, other is one which you are probably doing, which is stretched, so go for max-height and max-width properties.

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
0

best solutoin to give max-width and max-height to your class

.Comment_Image_Size {
    max-width:28px;
    max-height:32px;

}

Love Trivedi
  • 3,899
  • 3
  • 20
  • 26
0

The issue is that the original images are not the same aspect ratio. You need to specify the right height and width for each image to ensure that the maximum width/height is not exceeded (one will be less if not the right aspect ratio).

You may need to resize the images upon upload to have thumbnails that are the right size while preserving the aspect ratio How to resize images proportionally / keeping the aspect ratio?

Community
  • 1
  • 1
guymid
  • 1,186
  • 8
  • 11