简体   繁体   English

如何让html的内容占据整个浏览器window?

[英]How can I make the html content to occupy the entire browser window?

I have the below div in a html page which tries to render content from a different html page.我在 html 页面中有以下 div,该页面尝试从不同的 html 页面呈现内容。 The rendered html content occupies the entire width but not the height.渲染的 html 内容占据整个宽度,但不占据高度。 what needs to be changed in the style attribute to occupy the entire height available?样式属性中需要更改什么以占据整个可用高度?

Thank you!谢谢!

<div>
    <embed type="text/html" style="text-align:center;width:100%;height:100%"
       src="https://app.mytest.com/common/mydocuments.html">
</div>

Well, there are a lot of methods to achieve this in CSS, but the approach I love to use to achieve this is using full viewport height and width.嗯,在 CSS 中有很多方法可以实现这一点,但我喜欢用来实现这一点的方法是使用完整的视口高度和宽度。

embed {
  height: 100vh;
  width: 100vw;
}

it basically tells the browser to use the entire window for this tag.它基本上告诉浏览器为此标签使用整个 window。

and to make it fix you can use position: fixed;并使其修复,您可以使用position: fixed;

For the Html content to occupy the entire page just set the min-height to 100vh.I have attached a sample code for your reference also refer the link provided for further understanding https://www.freecodecamp.org/news/html-page-width-height/对于 Html 内容占据整个页面只需将 min-height 设置为 100vh。我附上了示例代码供您参考,也请参阅提供的链接以进一步了解https://www.freecodecamp.org/news/html-page -宽度-高度/

 <style> body { min-height: 100vh; max-width: 400px; margin: 0 auto; background-color:blue; } </style> <div> <h class="body">Sample Text <h> <div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM