html - iframe 中的样式图像

标签 html css iframe image

通过设置 iframe 的 src 属性,我在 iframe 中有一个图像:

<iframe src="path/to/my/image.jpg" class="myclass"></iframe>

iframe 具有固定的高度和宽度。我希望该图片的宽度填满 iframe,但它的高度将与宽度成比例,这样用户就可以向下滚动 iframe 以查看图片的其余部分。
我该怎么做?
编辑:JSFiddle 链接 http://jsfiddle.net/2LExA/

最佳答案

我将 iframe 的 src 设置为名为 show_image.php 的页面,并将图像 url 作为查询字符串传递:

<iframe src="show_image.php?src=path/to/image.jpg" class="foobar"></iframe>

然后在 show_image.php 中,我放置了一个 img,其 src 设置为查询字符串,宽度设置为 100%:

<img src="<?php echo $_GET['src']; ?>" style="width:100%" />

完成! 感谢 lukeocom 提示我应该将图像放在单独的页面中。

关于html - iframe 中的样式图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15082459/

相关文章:

html - 在 html5 中使用 ul li 两次

javascript - beforeunload事件之前的Angular8 IFrame

java - X-Frame-Options 支持同一域的不同子域

javascript - 避免多次加载 jquery

javascript - 展开/收缩菜单栏

jquery - 如何选择50px或更高的h2标签并更改它们的css?

jquery - 不安全的 JavaScript 尝试使用 URL 访问框架。它是本地的

html - CSS 动画不起作用

javascript - 需要javascript代码的解释

html - 内部div浮出父div