我一直在尝试缩放图像以适合使用CSS的div。如果图像的宽度和高度相等,则效果很好,但是当宽度大于高度时,反之亦然。
这是我怎么做到的?

#container{
   -webkit-border-radius: 80px 80px 80px 80px; /*makes the div a  nice circle */
   -moz-border-radius: 80px 80px 80px 80px;
    border-radius: 80px 80px 80px 80px;
    float:left;
    height:150px;
    width:150px;
    -webkit-box-shadow: 0 1px 3px rgba(0,0,0, .3);
   -moz-box-shadow: 0 1px 3px rgba(0,0,0, .3);
   box-shadow: 0 1px 3px rgba(0,0,0, .3);
}

#picture{
   -webkit-border-radius: 80px 80px 80px 80px; /*makes the image a nice circle*/
   -moz-border-radius: 80px 80px 80px 80px;
    border-radius: 80px 80px 80px 80px;
    float:left;
    height:auto;
    width:100%;
    cursor:hand;
    cursor:pointer;
}

最佳答案

img{
    max-width:100%;
    max-height:100%;
}


这将使图像始终是最大图像之一。

关于css - CSS中图像的高度和宽度缩放,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18561358/

10-09 07:44