简体   繁体   English

如何防止流体容器中显示的图像被裁剪

[英]How to prevent image in fluid container displayed cropped

Please take a look of the following code and result. 请看下面的代码和结果。

html: 的HTML:

<div id="social_media">
    <ul class="social">
        <li><a href="#"><img src="facebook.png"></a></li>
        <li><a href="#"><img src="twitter.png"></a></li>
        <li><a href="#"><img src="gplus.png"></a></li>
        <li><a href="#"><img src="linkedin.png"></a></li>
    </ul>
</div>

css: CSS:

#social_media {
    width:70%;
    float: left;
    text-align:center;
}

ul.social{
    margin: 0; padding: 0;
    list-style-type: none;
}
ul.social li{
    width: 14%;
    margin: 0 5.5%;
    display: inline-block;
    float: left;
    text-align: center;
}

result: 结果:

在此处输入图片说明

Is it possible to keep this fluid layout, but prevent images displayed like that. 是否可以保持这种流畅的布局,但防止这样的图像显示。 You'll notice that the bottom edges of the images is displayed as if it's cropped. 您会注意到,图像的底部边缘显示为裁剪后的样子。 The second and third images get cropped on the right side too. 第二张和第三张图像也会在右侧裁剪。

UPDATE: Please take a look of the live example http://jsfiddle.net/ktsixit/bcceC/embedded/result/ The list is placed in a fluid container ad I think that's the key to this isuue/solution. 更新:请看一个实时示例http://jsfiddle.net/ktsixit/bcceC/embedded/result/该列表放置在一个可变容器广告中,我认为这是解决此问题/解决方案的关键。

SOLUTION: This turn to be a firefox issue. 解决方案:这变成了Firefox问题。 Any suggestions about how to fix that are welcomed... 任何有关如何修复的建议都受到欢迎...

ul.social{
    margin: 0; padding: 0;
    list-style-type: none;
}
ul.social li{
    width: 14%;
    margin: 0 5.5%;
    display: inline-block;
    float: left;
    text-align: center;
}

ul.social li img {
    width: 100%;
    height: auto;
}

I believe you need to tell your images to fit the width of their parent. 我相信您需要告诉您的图片适合其父级的宽度。 As at the moment the image appears too large for it's parent container, therefore cannot be shown fully. 目前,图片对于其父容器而言显得太大,因此无法完全显示。 This should fix your issue and ensure that the images will fit the container when going down to smaller screens etc. 这应该可以解决您的问题,并确保在下到较小的屏幕等时,图像适合容器。

Sometimes this is simply how images get scaled down by browsers. 有时,这仅仅是浏览器按比例缩小图像的方式。 Did you make sure that your image files are not broken or something? 您是否确定图像文件没有损坏?

Anyway, there is an experimental specification called image-rendering which only works in the latest browser version except IE. 无论如何,有一个称为image-rendering的实验性规范,该规范仅在IE以外的最新浏览器版本中有效。 I can't recommend using this, but want to keep this option open for you. 我不建议您使用此选项,但希望为您保持打开状态。

img[src$=".gif"], img[src$=".png"] {
   image-rendering: -moz-crisp-edges;         /* Firefox */
   image-rendering:   -o-crisp-edges;         /* Opera */
   image-rendering: -webkit-optimize-contrast;/* Webkit (non-standard naming) */
   image-rendering: crisp-edges;
   -ms-interpolation-mode: nearest-neighbor;  /* IE (non-standard property) */
}

Read a more detailed text here: image-rendering on MDN 在此处阅读更详细的内容: 在MDN上进行图像渲染

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM