如何让Electron WebView填充指定大小?
How to make Electron WebView fill specified size?
我已经尝试将 Electron WebView 添加到基本应用程序并在其上设置 minwidth 和 minheight ,如下所示。虽然它加载时总是以 784px X 150px
<webview id="webpage" src="https://www.duckduckgo.com/" autosize="on" minwidth="800px" minheight="1200px"></webview>
其他人也报告过这个问题。在原子讨论中 webview autosize.
似乎 'autosize' 并没有对最终的 window 尺寸说出最后一句话; css 参数可能会干扰并改变结果。
针对此问题提出的一些 css 解决方法可能会有所帮助:
将 html 和正文宽度设置为 100%:
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
在 webview 中设置视口相对单位 css:
webview {
display: block; /* iframes are inline by default */
border: none; /* Reset default border */
height: 80vh; /* Viewport-relative units */
width: 95vw;
}
试试这个:
<div style="width:100%; height:100%">
<webview src="https://www.google.com/" autosize="on" style="min-width:900px; min-height:1200px"></webview>
</div>
我已经尝试将 Electron WebView 添加到基本应用程序并在其上设置 minwidth 和 minheight ,如下所示。虽然它加载时总是以 784px X 150px
<webview id="webpage" src="https://www.duckduckgo.com/" autosize="on" minwidth="800px" minheight="1200px"></webview>
其他人也报告过这个问题。在原子讨论中 webview autosize.
似乎 'autosize' 并没有对最终的 window 尺寸说出最后一句话; css 参数可能会干扰并改变结果。
针对此问题提出的一些 css 解决方法可能会有所帮助:
将 html 和正文宽度设置为 100%:
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
在 webview 中设置视口相对单位 css:
webview {
display: block; /* iframes are inline by default */
border: none; /* Reset default border */
height: 80vh; /* Viewport-relative units */
width: 95vw;
}
试试这个:
<div style="width:100%; height:100%">
<webview src="https://www.google.com/" autosize="on" style="min-width:900px; min-height:1200px"></webview>
</div>