【问题标题】:How to rescale image relative to its own size in HTML and CSS如何在 HTML 和 CSS 中相对于自身大小重新缩放图像
【发布时间】:2014-05-13 14:36:37
【问题描述】:

如何在 HTML 和 CSS 中相对于其自身大小重新缩放图像?

我希望将图像放大到自己大小的170%,或者将其缩小到自己大小的50%,而不是父元素的大小。

我试过了:

<div><img src="0001.svg" height="50%"></div>

它相对于其父元素的高度重新缩放。

【问题讨论】:

标签: html css


【解决方案1】:

这行得通:

<script>
function Start() {
OPIC = document.getElementById('PIC')
var x=OPIC.width, y=x=OPIC.height, pct=.7 // = 70%
OPIC.height=pct*y; OPIC.width=pct*x;
}
</script>
<body onload="Start()">
<img id='PIC' src=...>

但是使用 IE 和 Edge,我似乎失去了画面

【讨论】:

  • 我忘记了`
【解决方案2】:

为父 div 指定一些宽度。然后为图像指定宽度或高度以保持图像的纵横比。

这里是LINK

HTML:

   <div class="image_resize">
        <img src="http://www.sxc.hu/img/certified_images/crt_melaniemar.jpg" />
    </div>

CSS:

    .image_resize {
        width:260px;
    }
    .image_resize img {
        width:60%;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 2011-06-08
    • 2012-06-10
    • 2011-06-05
    • 2018-06-15
    • 2012-03-09
    相关资源
    最近更新 更多