Scaling Images Proportionally in CSS with Max-width

后端 未结 8 1427
余生分开走
余生分开走 2021-01-31 13:39

Right now, I\'m using max-width to scale images to fit. However, they don\'t scale proportionally. Is there a way to cause this to happen? I\'m open to Javascript/jQuery.

<
相关标签:
8条回答
  • 2021-01-31 14:31

    Using both width and max-width on the image screw up IE8.

    Put the width on your image and wrap it in a div that has the max-width. (Then curse MS.)

    0 讨论(0)
  • 2021-01-31 14:34

    hopefully it is not too late , but with this pease of code i managed to get proportional images in my gallery. it will take time to understand what is going on but try it and enjoy.

    <style>
    div_base {
        width: 200px; // whatever size you want as constrain unchangeable
        max-width: 95%; // this is connected to img and mus exist
    }
    div_base img {
        width: auto !important;  // very important part just have it there!
        height: 95%;  // and this one is linked to maxW above. 
    }
    </style>
    
    0 讨论(0)
提交回复
热议问题