gpt4 book ai didi

html - 汉堡菜单 100% 高度

转载 作者:太空宇宙 更新时间:2023-11-03 21:04:08 24 4
gpt4 key购买 nike

我正在为测试应用制作响应式汉堡菜单。我希望汉堡包菜单在打开时占据整个屏幕(高度的 100%)。

我试过媒体查询:.header .menu 高度到 100% 但它不起作用:

body {
margin: 0;
font-family: Helvetica, sans-serif;
background-color: #f4f4f4;
}

a {
color: #8C2635;
}

a:hover {
color: #8B8D33;
}


/* header */

.header {
background-color: #fff;
position: fixed;
height: 80px;
width: 100%;
z-index: 3;
}

.header ul {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: #fff;
}

.header li a {
display: block;
padding: 20px 20px;
text-decoration: none;
}

.header .logo {
display: block;
float: left;
font-size: 2em;
padding: 10px 20px;
text-decoration: none;
}


/* menu */

.header .menu {
clear: both;
max-height: 0;
text-align: center;
transition: max-height .2s ease-out;
position: relative;
top: -7px;
}


/* menu icon */

.header .menu-icon {
cursor: pointer;
display: inline-block;
float: right;
padding: 40px 20px;
position: relative;
user-select: none;
}

.header .menu-icon .navicon {
background: #333;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 18px;
}

.header .menu-icon .navicon:before,
.header .menu-icon .navicon:after {
background: #333;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}

.header .menu-icon .navicon:before {
top: 5px;
}

.header .menu-icon .navicon:after {
top: -5px;
}


/* menu btn */

.header .menu-btn {
display: none;
}

.header .menu-btn:checked~.menu {
max-height: 300px;
}

.header .menu-btn:checked~.menu-icon .navicon {
background: transparent;
}

.header .menu-btn:checked~.menu-icon .navicon:before {
transform: rotate(-45deg);
}

.header .menu-btn:checked~.menu-icon .navicon:after {
transform: rotate(45deg);
}

.header .menu-btn:checked~.menu-icon:not(.steps) .navicon:before,
.header .menu-btn:checked~.menu-icon:not(.steps) .navicon:after {
top: 0;
}

@media (min-width: 64em) {
.header li {
float: left;
}
.header li a {
padding: 30px 30px;
}
.header .menu {
clear: none;
float: right;
max-height: none;
}
.header .menu-icon {
display: none;
}
}
<header class="header">

<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>

<ul class="menu">
<li><a href="#work">HOME</a></li>
<li><a href="#about">SOBRE NÓS</a></li>
<li><a href="#careers">OBJETIVOS</a></li>
<li><a href="#contact">PARCEIROS</a></li>
<li><a href="#contact">CONTACTOS</a></li>
</ul>

</header>

最佳答案

对于 .header .menu-btn:checked~.menu 类,我将 height 设置为 100vh,还有 max-height 因为它只有 300px

body {
margin: 0;
font-family: Helvetica, sans-serif;
background-color: #f4f4f4;
}

a {
color: #8C2635;
}

a:hover {
color: #8B8D33;
}


/* header */

.header {
background-color: #fff;
position: fixed;
height: 80px;
width: 100%;
z-index: 3;
}

.header ul {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: #fff;
}

.header li a {
display: block;
padding: 20px 20px;
text-decoration: none;
}

.header .logo {
display: block;
float: left;
font-size: 2em;
padding: 10px 20px;
text-decoration: none;
}


/* menu */

.header .menu {
clear: both;
max-height: 0;
text-align: center;
transition: max-height .2s ease-out;
position: relative;
top: -7px;
}


/* menu icon */

.header .menu-icon {
cursor: pointer;
display: inline-block;
float: right;
padding: 40px 20px;
position: relative;
user-select: none;
}

.header .menu-icon .navicon {
background: #333;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 18px;
}

.header .menu-icon .navicon:before,
.header .menu-icon .navicon:after {
background: #333;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}

.header .menu-icon .navicon:before {
top: 5px;
}

.header .menu-icon .navicon:after {
top: -5px;
}


/* menu btn */

.header .menu-btn {
display: none;
}

.header .menu-btn:checked~.menu {
max-height: 100vh;
height: 100vh;
}

.header .menu-btn:checked~.menu-icon .navicon {
background: transparent;
}

.header .menu-btn:checked~.menu-icon .navicon:before {
transform: rotate(-45deg);
}

.header .menu-btn:checked~.menu-icon .navicon:after {
transform: rotate(45deg);
}

.header .menu-btn:checked~.menu-icon:not(.steps) .navicon:before,
.header .menu-btn:checked~.menu-icon:not(.steps) .navicon:after {
top: 0;
}

@media (min-width: 64em) {
.header li {
float: left;
}
.header li a {
padding: 30px 30px;
}
.header .menu {
clear: none;
float: right;
max-height: none;
}
.header .menu-icon {
display: none;
}
}
<header class="header">

<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>

<ul class="menu">
<li><a href="#work">HOME</a></li>
<li><a href="#about">SOBRE NÓS</a></li>
<li><a href="#careers">OBJETIVOS</a></li>
<li><a href="#contact">PARCEIROS</a></li>
<li><a href="#contact">CONTACTOS</a></li>
</ul>

</header>

关于html - 汉堡菜单 100% 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55634211/

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