简体   繁体   English

图像以半宽显示

[英]Image is shown in half width

I'm completing a FrontEnd project, and I'm using Bootstrap 3 for the grid system. 我正在完成一个FrontEnd项目,我正在使用Bootstrap 3作为网格系统。

Now, I'm also using art direction using the picture element, but I have a problem with this images because, every time I added this source element: <source media="(min-width: 800px)" srcset="images/web-development.jpg 1x, images/web-development_2x.jpg 2x"> , the picture is displayed 50% of the size of the picture. 现在,我也使用图片元素使用艺术指导,但我对这个图片有问题,因为每次我添加这个源元素: <source media="(min-width: 800px)" srcset="images/web-development.jpg 1x, images/web-development_2x.jpg 2x"> ,图片显示图片大小的50%。 Does anyone know why might this happen? 有谁知道为什么会发生这种情况?

<section class="row">
<div class="col-md-12">
<picture>
<source media="(min-width: 800px)" srcset="images/web-development.jpg 1x, images/web-development_2x.jpg 2x">
<source media="(max-width: 799px)" srcset="images/web-development-small_1x.jpg 1x, images/web-development-small_2x.jpg 2x">
<img src="images/web-development.jpg" class="img-responsive center-block" alt="Common desktop of a developer">
</picture>
</div>
</section>

I've also tried like this and the same result happens 我也尝试过这样的结果,同样的结果发生了

<section class="row">
<div class="col-md-12">
<picture>
<source media="(max-width: 799px)" srcset="images/web-development-small_1x.jpg 1x, images/web-development-small_2x.jpg 2x">
<img src="images/web-development.jpg" srcset="images/web-development.jpg 1x, images/web-development_2x.jpg 2x" class="img-responsive center-block" alt="Common desktop of a developer">
</picture>
</div>
</section>

Have a read on srcset: https://webkit.org/demos/srcset/ 阅读srcset: https ://webkit.org/demos/srcset/

The reason you are getting 50% smaller is normal, the higher the pixel ratio / density 2x, 3x, 4x and so on, the smaller the image will display because monitor resolution is fix. 您缩小50%的原因是正常的,像素比率/密度2x,3x,4x等越高,图像显示的越小,因为显示器分辨率得到修复。

When you apply image with 1x solution will be the default dimension (eg 100px by 100px), when the resolution is doubled, in this case 2x you will need 200px by 200px to maintain the same size. 使用1x解决方案应用图像时将是默认尺寸(例如100px×100px),当分辨率加倍时,在这种情况下2x,您需要200px乘200px才能保持相同的尺寸。

I finally found an answer. 我终于找到了答案。

I created my own class in my style.css, and instead of adding max-width: 100%; 我在style.css中创建了自己的类,而不是添加max-width:100%; I added it width: 100%. 我加了宽度:100%。

And the problem was solved. 问题解决了。

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

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