Dar*_*tex 5 html css iframe image
通过设置 iframe 的 src 属性,我在 iframe 中有一个图像:
<iframe src="path/to/my/image.jpg" class="myclass"></iframe>
Run Code Online (Sandbox Code Playgroud)
iframe 具有固定的高度和宽度。我希望该图像的宽度填充 iframe,但其高度将与宽度成正比,因此用户可以向下滚动 iframe 以查看图像的其余部分。
我该怎么做呢?
编辑:JSFiddle 链接http://jsfiddle.net/2LExA/
您主要使用 iframe 来显示一个单独的 html 页面,其中包含图像。因此,您可以使用该页面的 css 来设置图像的样式。您可以使用 css 来设置 iframe 宽度的样式,但不能设置其内容的样式。
您的另一种选择是将图像放置在 div 中,并相对于该 div 设置图像的样式。
html
<div><img src="yourimg" /></div>
Run Code Online (Sandbox Code Playgroud)
CSS
div{width:600px;height:300px;}
img{width:50%;}
Run Code Online (Sandbox Code Playgroud)