Je crée un menu hamburger réactif pour une application de test. Je veux que le menu hamburger occupe tout l'écran (100% de la hauteur) lorsqu'il est ouvert.
J'ai essayé des requêtes multimédias: .header .menu hauteur à 100% mais cela ne fonctionne pas :
<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>
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;
}
}
3 Réponses :
Pour la classe .header .menu-btn: checked ~ .menu j'ai défini la hauteur sur 100vh , ainsi que le max-height car il ne s'agissait que de 300px
<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>
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;
}
}
height: 100vh= 100% de la hauteur de la fenêtre
height: 100%= 100% de la hauteur de l'élément parentUne chose que vous devez savoir: si vous utilisez% pour la marge verticale ou padding, le% sera calculé sur la largeur de l'élément parent, pas la hauteur.
Voir une belle page ici pour les unités CSS: http://css-tricks.com/the-lengths-of-css/ < / a>
Copié à partir de Mise en forme du sélecteur HTML et BODY à hauteur: 100%; vs en utilisant 100vh
Vous pouvez utiliser calc dans ce cas:
.header .menu-btn:checked~.menu {
max-height: calc(100vh - 80px);
}