简体   繁体   English

如何在缩略图上保留图像尺寸

[英]how to keep image dimensions on thumbnail

I'm looking for a way to show thumbnails in cart. 我正在寻找一种在购物车中显示缩略图的方法。 Thumbnailas are created in server for 130x130bx size keeping scale. Thumbnailas是在服务器中创建的,尺寸为130x130bx。 Returned thumbnail width or height (which is bigger) is 130px always. 返回的缩略图宽度或高度(更大)始终为130px。 For non square images smaller dimension is proportionally less. 对于非方形图像,较小的尺寸按比例较小。

Code below is used to show images in browser. 下面的代码用于在浏览器中显示图像。 if image height and width are very different, images look very bad. 如果图像高度和宽度非常不同,图像看起来非常糟糕。 Image properties show that pen image is returned as 130px × 26px as expeced (and looks good in firebug) but browser has scaled it to 130x130 px producing bad image. 图像属性显示笔图像返回为130px×26px(并且在firebug中看起来很好),但浏览器已将其缩放到130x130像素,从而产生不良图像。

How to disable this scaling so that image is displayed as 130x26 as returned from server ? 如何禁用此缩放以使图像显示为从服务器返回的130x26?

.picture {
    background: none repeat scroll 0 0 #FFFFFF;
    display: block;
    float: left;
    height: 130px;
    line-height: 130px;
    margin: 0 20px 15px 0;
    overflow: hidden;
    position: relative;
    text-align: center;
    width: 130px;
}

<a class="picture ui-corner-all" rel="product" href="/Store/Details?product=340618">
<img class="ui-corner-all" alt="" src="/Store/Thumb?product=340618&size=130">
</a>

ASP .NET / MONO MVC2 is used in server. ASP .NET / MONO MVC2用于服务器。 jquery-ui is used in browser. jquery-ui用于浏览器。

Update 更新

I changed .picture img style as suggested in answers. 我按照答案中的建议改变了.picture img风格。 Now pen style thumb ( width is much bigger than height) show correctly. 现在笔式拇指(宽度比高度大得多)显示正确。 Bottle thumb ( height is much bigger than width) are only partly visible. 瓶拇指(高度远大于宽度)仅部分可见。 How to make this image nicer so that any image fits to thumb and keeps its proportions? 如何使这个图像更好,以便任何图像适合拇指并保持其比例?

css CSS

in your Site.css file, line 711, 在您的Site.css文件中,第711行,

.picture img {
  height: auto; /* change this to 'auto'*/
  max-width:130px; /* add this for 'making sure'*/
  vertical-align: middle;
  width: 100%;
}

Try this out 试试吧

If you still want the border beeing visible, change image max-width to 128px 如果您仍希望可见边框,请将图像最大宽度更改为128px

For a perfect layout of your images witch will resize to biggest smallest proportions. 为了完美的图像布局,女巫将调整到最小的比例。

.picture img {
  border-width: 0;
  height: auto;
  max-height: 130px;
  max-width: 130px;
  vertical-align: middle;
  width: auto;
}

carry on 继续

Change the class: 改变班级:

.picture img {
  height: 100%;
  vertical-align: middle;
  width: 100%;
}

and remove the height: 100%; 并删除height: 100%; . You might want to set border-width: 0px; 您可能想要设置border-width: 0px; as well =) 以及=)

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

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