html - 使用 CSS 设置 div 高度以适应浏览器

标签 html css

我在容器 div 中有两个 DIV,我需要将它们都设置为适合浏览器窗口,如下所示,但它不适合我的代码,请给我一个解决方案建议

enter image description here

我的样式表代码

 html, body {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;

            }

.container {
    height: auto;
    width: 100%;
}
.div1 {
    float: left;
    height: 100%;

    width: 25%;
}
.div2 {
    float: left;
    height: 100%;
    width: 75%;
}

正文

<body>
<div class="container">
  <div class="div1"></div>
  <div class="div2"></div>
</div>

最佳答案

你也可以使用 viewport percentages如果您不关心老式 IE。

高度:100vh;

关于html - 使用 CSS 设置 div 高度以适应浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18934141/

相关文章:

html - 如何将 Bootstrap 开关从 767 更改为移动设备? 768?

javascript - 导航栏已扩展但有一个子菜单总是折叠

CSS 菜单 - 父节点中的事件链接在焦点位于子节点上时更改颜色

html - div调整大小而不推送内容

html - 以未损坏的 border-radius 滚动

javascript - IE 和 Chrome 中选择选项的边距不起作用

html - 我可以在 HTML5 Canvas 中使用字 rune 本颜色吗?

javascript - 将 Node.js 与本地服务器相结合

CSS:具有 2 列的全屏流体布局

html - 滚动时背景高度全屏