css - 当 css 位于两个单独的文件中时修复 div 大小
问题描述
目标:使绿色容器与蓝色容器的高度相匹配。
我文件中的dashboard
div 类Dashboard.js
不适合100vh
我在DashboardLayout.js
div 类中设置的内容:
<div className="dashboard__layout">
<div className="dashboard__layoutLeft">
<div className="linkspace__container">
<button>{user[0].toUpperCase()}</button>
<button className="add__profileButton">+</button>
</div>
</div>
<div className="dashboard__layoutRight">
<Header {...props} />
{props.children}
</div>
</div>
.dashboard__layout {
display: flex;
min-width: 100%;
height: 100vh;
}
这里的Dashboard.js
文件和dashboard
我试图适应DashboardLayout
div 的类:
<div className="dashboard">
<div className="dash__left">
<Sidebar />
</div>
<div className="dash__middle">
<LinkButtonTypes />
<ContentContainer />
</div>
<div className="dash__right">
<PersonalUrl />
<PhoneMockup />
</div>
</div>
.dashboard {
display: flex;
position: relative;
justify-content: space-between;
max-width: 100%;
height: 100%;
-ms-overflow-style: none;
scrollbar-width: none;
background-color: blue;
}
解决方案
根据您可以在元素上提供的高度,您可以创建不同的解决方案。下面是一个使用 flexbox 创建多个相邻列的示例:
.parent {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 100vh;
}
.top-left {
background-color: red;
height: 20vh;
width: 20%;
}
.bottom-left {
height: 80vh;
width: 20%;
background-color: green;
}
.right {
height: 100vh;
width: 80%;
background-color: blue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div class="parent">
<div class="top-left"></div>
<div class="bottom-left"></div>
<div class="right"></div>
</div>
</body>
</html>
这是一个示例,您必须知道红色块的高度并使用绝对位置而不是 flexbox:
body {
display: flex;
}
.parent {
width: 20%;
position: relative;
height: 100vh;
}
.top-left {
background-color: red;
position: absolute;
height: 100px;
width: 100%;
}
.bottom-left {
box-sizing: border-box;
padding-top: 100px;
height: 100%;
width: 100%;
background-color: green;
}
.right {
height: 100vh;
width: 80%;
background-color: blue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div class="parent">
<div class="top-left"></div>
<div class="bottom-left"></div>
</div>
<div class="right"></div>
</body>
</html>
当然,您可以根据要传递的高度值创建尽可能多的变化。
编辑:您提供蓝色部分内容的最后一个变体:
body {
display: flex;
}
.parent {
width: 20%;
position: relative;
}
.top-left {
background-color: red;
position: absolute;
height: 100px;
width: 100%;
}
.bottom-left {
box-sizing: border-box;
padding-top: 100px;
height: 100%;
width: 100%;
background-color: green;
}
.right {
width: 80%;
background-color: blue;
font-size: 50px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div class="parent">
<div class="top-left"></div>
<div class="bottom-left"></div>
</div>
<div class="right">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod nulla
reprehenderit fugiat exercitationem molestias corporis. Officia quod atque
deserunt possimus architecto enim. Aperiam earum, neque animi quis
exercitationem cupiditate repellendus.
</div>
</body>
</html>
推荐阅读
- .net - 从图像字节数组创建画笔时出现 System.OutOfMemoryException
- c++ - 如何在 OpenMP 中为 if-else、increment 的任意数量的线程获得相同的并行输出?
- javascript - Vuetify,使用数据作为道具的标签上的三元,甚至断点大小?
- asp.net-mvc - 使用 Identity Server 4 asp.net core 2.2 实现 Swagger 授权
- angular - 找不到模块“打字稿”| 离子 4
- javascript - 返回按钮(谷歌浏览器)需要放两次才能返回,如何解决这个问题?
- java - 选择设计模式时的困境
- c# - 方法的参数顺序(例如命名、参数、输入、输出、可选)是什么?
- scala - NoSuchMethodError:org.apache.spark.internal.Logging
- angular5 - 如何在 Angular 5 绑定中同时获取内容的值和名称?