【问题标题】:using img element with cover使用带封面的 img 元素
【发布时间】:2014-04-06 16:41:10
【问题描述】:

我想以相同的比例显示图像。但是图像大小会有所不同。可能是 16:10 或 10:10 的宽高比。有些图像看起来是垂直的,有些图像看起来是水平的。

我用 div 做了背景封面中心。但是我必须用它来 img 元素。

如何使用 img 做到这一点?

div.image-content
{
     width: 210px;
     margin: 15px;
     float: left;
     height: 210px;
     overflow: hidden;
     background: no-repeat center center;
     background-size: cover;
     -webkit-background-size: cover;
     -moz-background-size: cover;
     -o-background-size: cover; 
 }

【问题讨论】:

    标签: css image background-image


    【解决方案1】:

    只使用一个维度。 width:210px 或 height:210px

    如果您只指定一个维度,则另一个维度将按比例缩放。

    【讨论】:

    • 但照片已损坏
    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2016-01-07
    • 2021-06-04
    • 1970-01-01
    相关资源
    最近更新 更多