OGeek|极客世界-中国程序员成长平台

标题: html - 如何将图片的宽度调整为其 webview 的宽度 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:36
标题: html - 如何将图片的宽度调整为其 webview 的宽度

我有一个特定大小的 WebView :

    let webviewwidth:CGFloat=self.view.frame.width * 0.85;
    let webviewheigth:CGFloat=(self.view.frame.height - navbarHeigth) * 0.85;

    myWebView = UIWebView(frame: CGRectMake(0, navbarHeigth , webviewwidth, webviewheigth));

内容为:

<img src="myimage.jpg" width=????? alt="" border=0><br>

如何将图像的大小 (?????) 设置为其 webview 的大小? 将 HTML 中的宽度设置为 webviewsize 时,它​​会很大,因为 webview 的宽度以点为单位而不是像素。

有什么提示吗?



Best Answer-推荐答案


这是我在 webview 中用于 img 的 css

img {max-width: 100%;height: auto;margin-left: auto;margin-right: auto;}

如果您希望每个 img 宽度为 100%,只需将 max-width 替换为 width

关于html - 如何将图片的宽度调整为其 webview 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33410554/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4