为什么我的列表堆叠在彼此之上而不是彼此之上

时间:2017-04-14 22:47:44

标签: html css list css-position

我正在尝试制作一个在屏幕上水平且在手机上垂直的菜单。 虽然在电话上,但是李彼此堆叠而不是彼此叠加。

我试图改变“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>

1 个答案:

答案 0 :(得分:1)

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>