css - css中的图像高度和宽度缩放

标签 css

我一直在尝试使用 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/

相关文章:

html - Chrome 21 上的单选按钮白色背景、flash 对象和 iFame

html - 使用 Sandbags 在 Chrome/Safari 中文本覆盖图像,而不是 FF 或 IE

css - 使用 CSS text-transform 时避免微米符号 μ 显示为 M : uppercase

javascript - Canvas fillRect 高度和宽度总是倾斜/扭曲

javascript - 如何使用增量+选项(或可见性)在javascript上实现可见性

Javascript:模拟 IE 中图像的 maxWidth 和 maxHeight

javascript - 为菜单下方的脚本代码创建一个循环

css - 如何修复 bootstrap 3 中的 btn 宽度?

php - 布局 CSS 在 Safari 中完美运行但在 Firefox 中运行不佳?

css - 如何强制外部 div 扩展到内部 div 的高度?