编程宝库 - 技术改变世界
编程宝库
编程宝库提供了 JS 在线测试工具,可在线测试 JavaScript 代码,你可以在代码编辑器中输入 JavaScript 代码并点击运行查看结果。
源代码
点击运行
<!DOCTYPE html> <html> <head> <style> html, body { height: 100%; } img.one { height: auto; width: auto; } img.two { height: 50%; width: 50%; } </style> </head> <body> <h1>以百分比设置元素的高度和宽度</h1> <p>请调整浏览器窗口大小以查看效果。</p> <p>原始图像:</p> <img class="one" src="http://static.codebaoku.com/pics/f3/4d/f34de5cde0d4e0e3d958176104e9f951.jpeg" width="300" height="300"><br> <p>尺寸调整后的图像(以百分比计):</p> <img class="two" src="http://static.codebaoku.com/pics/f3/4d/f34de5cde0d4e0e3d958176104e9f951.jpeg" width="300" height="300"> </body> </html>
运行结果