Reputation: 65
I want to add padding to my "a" element which will decide the height for the parent div. Although if I add it, the parent div remains unaffected. I cannot seem to figure it out at all.
It is a hamburger navbar menu. So when I click my icon, it should bring the navbar down and should be the same height that the "a" tag provides through padding.
<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;
}
Upvotes: 0
Views: 90
Reputation: 22919
You need to change the height
from a fixed value to auto
here.
.side-menu-open {
height: auto;
}
By default, a
is an inline element. Top and bottom padding will not apply. You can change the display type to inline-block
.
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;
}
<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>
Upvotes: 1