gpt4 book ai didi

html - 如何使用 100vh 创建响应式网页

转载 作者:行者123 更新时间:2023-11-28 15:00:51 24 4
gpt4 key购买 nike

我需要创建一个使用 100vh 或占用 100% 屏幕高度和宽度(无滚动)的网页。我创建了一个容器 (height:100vh),其中包含所有内容,在该容器中,我需要其中的所有内容进行响应。

设计理念: enter image description here

外部容器高度为 100vh,我需要内部容器响应:

#root {
position: relative;
height: 100vh;
overflow: hidden;
}

#root-inner-container {
width: 100%;
}

我遇到的问题是使用 100vh,容器内的内容无法保持响应并容易溢出。

Jsfiddle 到我目前所拥有的:https://jsfiddle.net/fm6hmgpk/

最佳答案

flex 解决方案

body {
margin: 0;
color: white;
}

.container {
background: grey;
width: 100vw;
height: 100vh;
}

.navbar {
height: 15vh;
background: darkblue;
margin: 0 10px;
}

.bottom {
background: lightgrey;
height: 85vh;
margin: 0 10px;
display: flex;
}

.left-bottom {
background: red;
width: 70%;
display: flex;
flex-direction: column;
}

.right-bottom {
flex: 1;
background: lightgrey;
}

.content-list {
display: flex;
height: 80%;
background: maroon;
}

.text {
flex: 1;
background: green;
}

.content {
width: 80%;
background: orange;
}

.list {
flex: 1;
}
<div class="container">
<div class="navbar">
NAVBAR
</div>
<div class="bottom">
<div class="left-bottom">
<div class="content-list">
<div class="content">
CONTENT
</div>
<div class="list">
LIST
</div>
</div>
<div class="text">
TEXT
</div>
</div>
<div class="right-bottom">
IMAGE
</div>
</div>
</div>

计算:(针对滚动问题)

<body>默认 margin:8px;和你的 border:2px solid black;总和为 10px所以我们需要扣除两次10px

因此 height: calc(100vh - 20px);

编辑:

要使其响应,您需要摆脱 fixed px对您的值(value) li

li {}

#root {
display: flex;
position: relative;
height: calc(100vh - 20px);
border: 2px solid black;
}

#root-inner-container {
flex: 1;
width: 100%;
display: flex;
}

.app-container {
flex: 1;
display: flex;
}

.div-1,
.div-2 {
flex: 1;
display: flex;
}

ul {
flex: 1;
display: flex;
flex-direction: column;
}

li {
flex: 1;
border: 1px solid red;
}
<div id="root">
<div id="root-inner-container">
<div class="app-container">
<div class="div-1">
<ul>
<li>div 1 - One</li>
<li>div 1 - Two</li>
<li>div 1 - Three</li>
<li>div 1 -Four</li>
</ul>
</div>

<div class="div-2">
<ul>
<li>div 2 - One</li>
<li>div 2 - Two</li>
<li>div 2 - Three</li>
<li>div 2 -Four</li>
</ul>
</div>
</div>
</div>
</div>

关于html - 如何使用 100vh 创建响应式网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50196517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com