li>填充不填充父li div

时间:2018-06-02 03:25:21

标签: html css

我想在我的" a"中添加填充。将决定父div的高度的元素。虽然如果我添加它,父div仍然不受影响。我似乎无法弄明白。

这是一个汉堡包导航栏菜单。因此,当我点击我的图标时,它应该将导航栏关闭,并且应该与" a"标签通过填充提供。

<div id="side-menu" class="side-nav" v-bind:class="{'side-menu-open': isOpen}">
    <ul class="side">
        <li class="side"><a href="#">Home</a></li>
        <li class="side"><a href="#">About</a></li>
        <li class="side"><a href="#">Projects</a></li>
        <li class="side"><a href="#">Contact</a></li>
    </ul>
</div>


li.side {
    display:inline-block;
    margin-right: -4px;
}

li.side a {
    padding: 3em 2em;
    border-bottom: 1px solid #333;
    display: block;
    color: #fff;
    text-decoration: none;
    transition: 0.3s ease;
}

li.side a:first-child {
    border-top: 1px solid #333;
}

li.side a:hover {
    background-color: #333;
    transition: 0.3s ease;
}

.side-nav {
    transition: 0.4s;
    background-color: #222;
    width: 100% !important;
    height:0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    overflow: hidden;
}

.open {
    transition: 1s;
}

.side-menu-open {
    height: 70px !important;
}

.open-slide {
    transition: 0.4s;
}

.open-slide:hover {
    cursor: pointer;
}

1 个答案:

答案 0 :(得分:1)

您需要在此处将height从固定值更改为auto

.side-menu-open {
    height: auto;
}

默认情况下,a是内联元素。顶部和底部填充不适用。您可以将显示类型更改为inline-block

&#13;
&#13;
li.side {
  display: inline-block;
  margin-right: -4px;
}

li.side a {
  padding: 3em 2em;
  border-bottom: 1px solid #333;
  color: #fff;
  text-decoration: none;
  transition: 0.3s ease;
  /* added */
  display: inline-block;
}

li.side a:first-child {
  border-top: 1px solid #333;
}

li.side a:hover {
  background-color: #333;
  transition: 0.3s ease;
}

.side-nav {
  transition: 0.4s;
  background-color: #222;
  width: 100% !important;
  /*height: 0;*/
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  overflow: hidden;
}

.open {
  transition: 1s;
}

.side-menu-open {
  height: auto !important;
}

.open-slide {
  transition: 0.4s;
}

.open-slide:hover {
  cursor: pointer;
}
&#13;
<div id="test">
  <div id="side-menu" class="side-nav" v-bind:class="{'side-menu-open': isOpen}">
    <ul class="side">
      <li class="side"><a href="#">Home</a></li>
      <li class="side"><a href="#">About</a></li>
      <li class="side"><a href="#">Projects</a></li>
      <li class="side"><a href="#">Contact</a></li>
    </ul>
  </div>
</div>
&#13;
&#13;
&#13;