简体   繁体   English

使用媒体查询调整图像大小

[英]Resizing images using media queries

Ok so I am making a filterable portfolio with bootstrap 3 and quicksand.js, I am using quicksand to filter the portfolio. 好的,我正在使用bootstrap 3和quicksand.js制作可过滤的投资组合,我使用流沙来过滤投资组合。 Now I had this working fine when my images were set widths and heights but when I change the width and height to 100% the sorting is weird, the images become bigger when they are sorting and this causes all kinds of glitches. 现在,当我的图像设置宽度和高度时,我的工作正常,但当我将宽度和高度更改为100%时,排序很奇怪,图像在排序时会变大,这会导致各种故障。

I had to use jquery migrate to get the sorting to work because the tutorial was so old, I dont know if this will be a contributing factor to my issue. 我不得不使用jquery迁移来使排序工作,因为教程太旧了,我不知道这是否会影响我的问题。

Here is old jsfiddle with the issue. 这是问题的问题。

Here is updated fiddle, with my max height + width fix 这是更新的小提琴,我的最大高度+宽度修复

Also you can check out this link which has the images at a fixed width, the sorting looks fine but then they stack on top of each other at lower screen sizes. 此外,您可以查看此链接该链接具有固定宽度的图像,排序看起来很好,但随后它们以较低的屏幕尺寸堆叠在一起。

UPDATE: Okay I have fixed the issue at desktop width by using max-width: 390px; 更新:好的我已经使用max-width: 390px;修复了桌面宽度的问题max-width: 390px; and max-height: 390px; max-height: 390px; on my .portfolio img class. 在我的.portfolio img类。 But now on lower resolutions (tablets etc) the images are bigger again. 但现在在较低分辨率(平板电脑等)上,图像再次变大。 Would the best way to fix this be with media queries or any suggestions? 解决此问题的最佳方法是媒体查询或任何建议吗? I realize now that bootstrap is designed to be mobile first but I am too far in my code I believe, what do you guys suggest. 我现在意识到引导程序是先设计为移动设备但是我的代码太过分了,我相信,你们有什么建议。

I resolved this issue by changing my portfolio img css to: 我通过将我的投资组合img css更改为:

.portfolio img {
    max-width: 100%;
    width: 100%;
    height: auto !important;
}

And used media queries to limit the width and height on the image at each viewport: 并使用媒体查询来限制每个视口处图像的宽度和高度:

@media (max-width:767px) {
    .portfolio img {
        max-width: 100%;
        max-height: 100%;
    }
}

@media (min-width:768px) {
    .portfolio img {
        max-width: 240px;
        max-height: 240px;
    }
}

@media (min-width:992px) {
    .portfolio img {
        max-width: 314px;
        max-height: 314px;
    }
}

@media (min-width:1200px) {
    .portfolio img {
        max-width: 380px;
        max-height: 380px;
    }
}

http://jsfiddle.net/uv634/2/ http://jsfiddle.net/uv634/2/

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

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