gpt4 book ai didi

html - 为什么没有显示的 child 的高度百分比不起作用?

转载 作者:行者123 更新时间:2023-11-28 14:50:17 25 4
gpt4 key购买 nike

我有以下代码片段,我不明白,为什么没有 display: flex 标签 a 的高度不会被考虑?

.topbar-container {
width: 100%;
height: 100px;
position: fixed;
top: 0;
background-color: #2d3e50;
z-index: 999;
display: flex;
}

.navi-container {
width: 100%;
height: 50px;
background-color: #119c7e;
position: fixed;
top: 100px;
z-index: 999;
display: flex;
justify-content: center;
}
@media (min-width: 992px) {
.navi-container .navi-menu {
width: 992px;
height: 100%;
color: #2d3e50;
overflow: hidden;
display: flex;
}
.navi-container .navi-menu a {
height: 100%;
}
}
.portfolio-container {
width: 992px;
position: absolute;
top: 155px;
}
.app-container {
display: flex;
width: 100%;
height: 100%;
flex-direction: column;
top: 0px;
position: relative;
align-items: center;
}
* {
padding: 0;
margin: 0;
}
html,
body {
height: 100%;
width: 100%;
font-size: 14px;
font-family: 'Montserrat', sans-serif;
}
#root {
box-sizing: border-box;
height: 100%;
width: 100%;
}
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>Cockpit</title>
<body cz-shortcut-listen="true">
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="root">
<div class="app-container">
<div class="topbar-container"></div>
<div class="navi-container">
<section class="navi-menu"><a>DASHBOARD</a><a>COINS</a></section>
</div>
<div class="portfolio-container">
<p>
Lorem
</p>
</div>
</div>
</div>
</body>
</html>

当我从样式中删除 display: flex 时:

.navi-container .navi-menu {
width: 992px;
height: 100%;
color: #2d3e50;
overflow: hidden;
display: flex;
}
.navi-container .navi-menu a {
height: 100%;
}

那么height: 100%;不生效?为什么?

最佳答案

删除 display: flex来自 .navi-container .navi-menu并添加 display: inline-blocka .默认 <a>内联显示。为了显示在中间,您需要从标签中删除高度并添加这些属性:

display: inline-block;
position: relative;
top: 50%;
transform: translateY(-50%);

.topbar-container {
width: 100%;
height: 100px;
position: fixed;
top: 0;
background-color: #2d3e50;
z-index: 999;
display: flex; }

.navi-container {
width: 100%;
height: 50px;
background-color: #119c7e;
position: fixed;
top: 100px;
z-index: 999;
display: flex;
justify-content: center; }
@media (min-width: 992px) {
.navi-container .navi-menu {
width: 992px;
height: 100%;
color: #2d3e50;
overflow: hidden;
}
.navi-container .navi-menu a {
display: inline-block;
position: relative;
top: 50%;
transform: translateY(-50%);} }

.portfolio-container {
width: 992px;
position: absolute;
top: 155px; }

.app-container {
display: flex;
width: 100%;
height: 100%;
flex-direction: column;
top: 0px;
position: relative;
align-items: center; }

* {
padding: 0;
margin: 0; }

html,
body {
height: 100%;
width: 100%;
font-size: 14px;
font-family: 'Montserrat', sans-serif; }

#root {
box-sizing: border-box;
height: 100%;
width: 100%; }
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>Cockpit</title>

<body cz-shortcut-listen="true">
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="root">
<div class="app-container">
<div class="topbar-container"></div>
<div class="navi-container">
<section class="navi-menu"><a>DASHBOARD</a><a>COINS</a></section>
</div>
<div class="portfolio-container">
<p>
Lorem

</p>
</div>
</div>
</div>
</body>

</html>

关于html - 为什么没有显示的 child 的高度百分比不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51754288/

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