dthok9648 2015-03-20 14:46
浏览 34
已采纳

我如何保持Mozilla Firefox上的图像比例?

I used this code to retrieve and keep the ratio of an image:

<img class="r r-2x img-full " style="background:url('<?php echo $image; ?>') no-repeat top center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover;  background-size: cover;"/>

this solution works in IE and Chrome not in Mozilla Firefox where the image is not displayed. So how could I proceed? I tried with src="<?php echo $image; ?>", but the ratio is not respected

  • 写回答

1条回答 默认 最新

  • dongxibeng5324 2015-03-26 13:44
    关注

    Using img or div shouldn't matter. The only problem I see is that I have to apply a width and height on the element in order to view the image. The image stays in the correct aspect ratio though.

    With the img tag:

    <img class="r-r-2x-img-full" border="0" style="display:block; width: 100px; height: auto; background:url('<?php echo $image; ?>') no-repeat top center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover;  background-size: cover;" />
    

    With the div tag:

    <div class="r-r-2x-img-full" border="0" style="display:block; width: 100px; height: auto; background:url('<?php echo $image; ?>') no-repeat top center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover;  background-size: cover;" />
    

    Hope this helped you out :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算