我正在尝试制作一个菜单,该菜单在屏幕上是水平的,而在电话上是垂直的。
尽管在电话中,li彼此堆叠,而不是彼此堆叠。
我试图更改“ position:absolute”,但这会使我的菜单消失。
有办法解决这个问题吗?
.menubar {
display: flex;
justify-content: space-between;
width: 86.3vw;
}
.menurow {
position: fixed;
left: 1.52vw;
bottom: -0.9vh;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
h3 {
position: absolute;
border: none;
background-color: transparent;
padding-bottom: 1vh;
color: black;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
font-size: 1.8vw;
text-transform: uppercase;
cursor: pointer;
display: inline-block;
bottom: 0vh;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
h3:hover {
bottom: 1.5vw;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.navigationmobile {
visibility: hidden;
}
/* phone */
@media(max-width: 480px) {
.menurow,
#contact,
#salaris,
#personeel {
visibility: hidden;
}
.navigationmobile {
visibility: visible;
z-index: 100;
}
.navigationmobile ul {
margin: 0;
padding: 2;
width: 500px;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
h3 {
border: none;
left: 1.65vw;
background-color: transparent;
padding-bottom: 1vh;
color: black;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
font-size: 1.8vw;
text-transform: uppercase;
cursor: pointer;
display: inline-block;
bottom: 0vh;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
}
<div class="menurow">
<ul class="menubar">
<li>
<h3 class="mobile-menu" data-menu="menu-1">Boekhouding</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-2" id="salaris">Salarisadministratie</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-3">Debiteurenbeheer</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-4" id="personeel">Personeelszaken</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-5">Mediation</h3>
</li>
</ul>
</div>
<div class="navigationmobile"><u>
<li><h3 class="mobile-menu" data-menu="menu-1">Boekhouding</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-2">Salarisadministratie</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-3">Debiteurenbeheer</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-4">Personeelszaken</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-5">Mediation</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-6">Contact</h3></li>
</u></div>
最佳答案
从position: absolute; bottom: 0vh;
删除h3
。由于li
位置从正常流程中删除了一个元素,因此可以防止absolute
在页面上具有预期的布局。
.menubar {
display: flex;
justify-content: space-between;
width: 86.3vw;
}
.menurow {
position: fixed;
left: 1.52vw;
bottom: -0.9vh;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
h3 {
border: none;
background-color: transparent;
padding-bottom: 1vh;
color: black;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
font-size: 1.8vw;
text-transform: uppercase;
cursor: pointer;
display: inline-block;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
h3:hover {
bottom: 1.5vw;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.navigationmobile {
visibility: hidden;
}
/* phone */
@media(max-width: 480px) {
.menurow,
#contact,
#salaris,
#personeel {
visibility: hidden;
}
.navigationmobile {
visibility: visible;
z-index: 100;
}
.navigationmobile ul {
margin: 0;
padding: 2;
width: 500px;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
h3 {
border: none;
left: 1.65vw;
background-color: transparent;
padding-bottom: 1vh;
color: black;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
font-size: 1.8vw;
text-transform: uppercase;
cursor: pointer;
display: inline-block;
bottom: 0vh;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
}
<div class="menurow">
<ul class="menubar">
<li>
<h3 class="mobile-menu" data-menu="menu-1">Boekhouding</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-2" id="salaris">Salarisadministratie</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-3">Debiteurenbeheer</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-4" id="personeel">Personeelszaken</h3>
</li>
<li>
<h3 class="mobile-menu" data-menu="menu-5">Mediation</h3>
</li>
</ul>
</div>
<div class="navigationmobile"><u>
<li><h3 class="mobile-menu" data-menu="menu-1">Boekhouding</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-2">Salarisadministratie</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-3">Debiteurenbeheer</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-4">Personeelszaken</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-5">Mediation</h3></li>
<li><h3 class="mobile-menu" data-menu="menu-6">Contact</h3></li>
</u></div>
关于html - 为什么我的列表彼此堆叠而不是彼此堆叠,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43420182/