The padding for the anchor tag within an li element is not expanding to fill the parent li element

I'm struggling to make the parent div adjust its height based on the padding I add to the "a" element. This is causing an issue in my hamburger navbar menu where I want the expanded navbar to match the height set by the padding on the "a" tag.

<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;
}

Answer №1

Make a modification to the height attribute by changing it from a fixed value to auto at this location.

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

By default, the element a is an inline element which does not support top and bottom padding. To enable these, you can switch 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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HTML checkbox utilizing JavaScript

<input type="checkbox" name="smoker"> Is there a way for JavaScript to determine whether the checkbox is checked or unchecked without making changes to the HTML code above? ...

Using Jquery Ajax to Implement Chained Select Dropdowns

As a newcomer to programming, I recently completed the jQuery course on CodeAcademy. Currently, I am attempting to create a chained select using jQuery's AJAX function to call a PHP page that executes a query on my database and outputs it to my main H ...

Changing background colors of dropdown items in VueJs

Currently grappling with understanding the intricacies of styling in web development (specifically VueJS). I am facing some challenges: I am dynamically rendering colored dropdowns filled with dropdown items. I am struggling to figure out how to change t ...

iOS search button with a unique blue outline border

On iOS, I'm seeing a strange blue border that I can't seem to get rid of. see image for reference I've exhausted all options like :focus and :active, but I can't pinpoint the source of the border. I've searched through different ...

Employ the CSS pseudo-element :before within a UL element to generate a vertical line

I'm currently working on a vertical menu with the capability of having submenus. My aim is to include a vertical line using CSS pseudo-element ::before along with border. The challenge I'm encountering is that the CSS is applying to the entire m ...

The functionality for determining whether the value isset as 'Yes' or 'No' is not functioning properly in my PHP form

I'm currently working on creating a combined 'Order Calculator / Order Form' using one php form. The calculator part of the form is functioning perfectly and accurately calculates the total for all 5 order options both on the live page and i ...

Seeking guidance on transitioning from the success/error method to the .then() method while leveraging AngularJS for developing a dynamic table

Recently, I encountered a situation where the suggestion was to utilize AngularJS for creating a dynamic table. The challenge is that I have no familiarity with AngularJS (or coding in general) and relied on an outdated tutorial. It appears that the outdat ...

Guide to automatically refreshing a page every 30 seconds for a total of 5 times

Is there a way to automatically refresh a page 5 times with a delay of 30 seconds between each refresh without causing the entire page to reload? I'm trying to avoid using the document.location.reload() JavaScript function as it reloads the entire pag ...

Enhancing User Experience: Use of Multiple Select Radio Buttons in Conjunction with Jquery UI Tabs and Mals

Whenever I select one radio button, I want all other radio buttons in each form with the same value to also change. I've been having trouble getting this functionality to work, so I created a JSFiddle for you to review here. Any assistance would be g ...

Is there a way to ensure that a child mimics the behavior of its parent when adjusting the opacity and visibility properties of both elements?

Apologies for the ambiguous title, as I am struggling to accurately convey the issue I am encountering. To clarify the problem, I have created a jsFiddle. In my current layout, all four divs have opacity: 1 and visibility: visible, while divs a and b both ...

Tips for positioning the cursor at the end of text within a contenteditable div tag

There seems to be a multitude of solutions available here How can one position the cursor at the end of text within an input or textbox element tag? Utilizing JavaScript to place the cursor at the end of text in a text input element Achieving the jQuery ...

Using CSS to duplicate images in multiple repetitions horizontally

In the process of developing a UHD project that involves showcasing large images, I have encountered limitations with iOS and certain mobile browsers. While stationary browsers pose no issue, iOS only supports PNG images up to 5 megapixels in resolution, w ...

Adding a block between two other blocks on a mobile device using Bootstrap 4

I am trying to achieve a specific layout on both desktop and mobile devices. On desktop, I want the layout to be structured as follows: [1][2] [3][2] The requirement is for column 2 to be the same height as columns 1 and 3 on desktop screens. For the mo ...

Creating a full width and height slider with a header menu that is responsive to all device screen sizes

Looking to create a full-width slider with a header that adjusts for all screen sizes, especially larger devices. I've been searching online but haven't found a satisfactory solution yet. If anyone has any ideas or tips on how to achieve this, pl ...

What is the best way to display an image right in the middle of the header?

My project consists of three main files - an HTML, a CSS, and a JS file. I have developed the HTML using the Bootstrap 5.1.3 framework. The issue I am facing pertains to the alignment of the clothing brand logo within the header section. Despite multiple ...

CSS media query specifically for mobile devices regardless of screen width

I've been trying to use a dragscroll plugin to scroll through content, but I've run into an issue where it doesn't work on mobile devices. By mobile devices, I mean those without a mouse cursor, like smartphones and tablets with touchscreen ...

Is it possible for me to execute index.html using React without relying on npm start and npx create-react-app?

As I dive into learning React on my own, I find myself tangled in confusion. My initial approach was to add React to my index.html using a script like this: //index.html <!DOCTYPE html> <html lang="en"> <head> <title> ...

An obstacle with Google fonts in NextJs - Only a single font is appearing

In my NextJs application, I've added a Google Fonts link to the HEAD section of the _app.js file. This link includes two different fonts. https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;700&family=Poppins:wght@400;700&display=swap H ...

Hovering over an element can trigger a dynamic swing animation effect

My objective is to animate an item to swing only when hovered over, utilizing CSS and jQuery, and of course, it should stop swinging when the mouse moves away. After browsing the web, I came across a code snippet that swings an element when the document i ...

Place picture in the bottom right corner of the div without using absolute positioning

I am looking for a way to position an image in the lower right corner of a div, but I want to avoid using absolute positioning. The reason for this is that when I use absolute positioning, the text wrap is affected due to the float right applied to the ima ...