简体   繁体   English

图片的高度和宽度设置为100%,无法在Android浏览器中正确调整大小。

[英]Image's height and width set to 100% not resizing properly in Android Browser.

I have the following html: 我有以下html:

   <div class="product-view row" data-id="505019">
   <a href="http://dev.shopious.com/items/505019/Kode--A032Bahan--spandex-korea-HQUkuran--fit-to-LRp69000">
      <img class="img-responsive" src="http://distilleryimage4.s3.amazonaws.com/6f1400c6a9cc11e3b5a512abfd23a3f4_6.jpg" data-src="http://distilleryimage4.s3.amazonaws.com/6f1400c6a9cc11e3b5a512abfd23a3f4_6.jpg" width="100%" height="100%">
   </a>
   </div>
</div>

I wanted essentially the image to adjust according to the width and height of the container. 我实质上希望图像根据容器的宽度和高度进行调整。 So I've set width="100%" and height="100%" . 因此,我设置了width="100%" and height="100%"

This works all fine on most major browsers such as chrome, firefox, opera, and even opera mini. 这在大多数主流浏览器(例如chrome,firefox,opera甚至Opera mini)上都可以正常工作。

However when I tried this on an android browser, it messes up. 但是,当我在Android浏览器上尝试此操作时,它陷入混乱。 Why is this? 为什么是这样? Here is the link to my website here . 这里是链接到我的网站在这里

use style="width:100%; height:100%;" 使用style="width:100%; height:100%;" instead. 代替。

in both cases make sure the parent element has constant size set, because 100% is supposed to be 100% of something. 在这两种情况下,请确保父元素设置了恒定的大小,因为100%应该是某物的100%。 if parent element has no width, then 100% of nothing is still nothing. 如果父元素没有宽度,则100%的内容仍为零。

major browsers have default user-agent styles, they can set parent size accordingly on their own therefore the 100% would work, im not sure if the mobile browser you tested it on has its user-agent styling, but you should always do it correctly and not rely on default styling. 主流浏览器具有默认的用户代理样式,它们可以自行设置父大小,因此100%可以使用,我不确定在其上测试过的移动浏览器是否具有用户代理样式,但您应始终正确进行设置而不依赖默认样式。

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

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