What could be causing the padding of my anchor element to extend outside the boundaries of its parent list

In the provided images, it is evident that the <li> element is failing to expand and is disregarding the padding of the parent

element.</p>
<p><a href="https://i.stack.imgur.com/4ZH65.png" rel="nofollow noreferrer"></a></p>
<p><a href="https://i.stack.imgur.com/l6bbv.png" rel="nofollow noreferrer"></a></p>
<p>The structure of the code is as follows:</p>
<pre><code>    <nav class="main-nav">
        <ul class="main-nav__items">
            <li class="main-nav__item">
                <a href="">Packages</a>
            </li>
            <li class="main-nav__item">
                <a href="">Customers</a>
            </li>
            <li class="main-nav__item main-nav__item--cta">
                <a href="">Start Hosting</a>
            </li>
        </ul>
    </nav>

The CSS being used is:

.main-nav {
  display: none;
}

.main-nav__items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.main-nav__item {
  display: inline-block;
  margin: 0 1rem;
}

.main-nav__item a,
.mobile-nav__item a {
  text-decoration: none;
  color: #0e4f1f;
  font-weight: bold;
  padding: 0.2rem 0;
}

I am seeking an explanation as to why the <li> element is not adjusting as expected (it does not have a fixed height so it should adjust).

Answer №1

When the <a> element is an INLINE element, the parent doesn't adjust to the padding, as it ignores it.

To fix this: simply change the inline element into an inline-block element by adding this CSS code:

.main-nav__item--cta a{
    display: inline-block
 }

By doing this, the parent will now adjust to the padding properly.

https://i.stack.imgur.com/fpEdY.png

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

What is the best method to enable horizontal scrolling within a div element by overflowing its content?

My layout looks like this: <div id='container'> <div id='cont1' style='width:150px'>Content 1</div> <div id='cont2' style='width:150px'>Content 2</div> <div id=' ...

Tips for displaying form data in a boostrap modal

One issue I am facing involves a form that collects a user's first and last name, along with a button that activates a bootstrap modal. When the button is clicked, the goal is to display the inputted data from the form within the modal window. The use ...

What are some creative ways to incorporate a variety of images into my website?

Currently working on a webpage and running into an issue. I have a div called "background" where I am loading several images using the <img>-tag. The problem is that the images are set to float:left;, causing them to wrap onto a new line as they can& ...

Ensuring proper functionality of JQModal when displayed above an iframe with the usage of ?wmode=

Here's an interesting one... I'm currently working on a site with JQModal and everything seems to be functioning properly except for the fact that the iframe appears on top of the modal. An easy fix is to append ?wmode=opaque at the end of the ...

Alteration in relational shift of division placement

My webpage is divided into three sections with the following proportions: 15% - 65% - 20% In the right section, there is a div with the ID alchemy. I want to set the height of this div using <div style="height:150px;">. However, when I set the heig ...

Disabling 'Input Number' feature is ineffective in Firefox browser

Is there a way to prevent the input value from changing when the up or down arrow is held, even if the input is disabled? I want to retain the arrows without allowing this behavior on Firefox. Give it a try: Press the up arrow. After 5 seconds, the input ...

css: centrally align a collection of items that are spaced evenly throughout the group

I have multiple divs inside a container that I want to evenly distribute horizontally: [container [obj1] [obj2] [obj3] [obj4] ] Additionally, I would like the container to be centered on the page My current CSS (stylus) code for the container is as foll ...

Populate JQuery fields dynamically based on changing name elements

I am working on a section that displays products dynamically fetched from a database using an ajax call. The results vary, some are single-row while others have multiple rows. Initially, I have a placeholder row of HTML on the main page for data entry whic ...

Make sure to close all your tags properly in PHP

Within my <textarea>, I am giving users the ability to submit content. The specific tags I want to allow include <b>, <i>,<blockquote>, and <del>. In order to prevent any unclosed tags since this content will be displayed on t ...

Vanishing Submit Button with CSS

In my input submit button, I have included the following code: <input class="buttons" type="button" onclick="javascript:jQuery(xxxx)" style="font-size: 12px;" value="Invite to Bid"> Additionally, there is a CSS function that adds an elegant "Go" im ...

Why isn't a single click enough to activate an anchor generated with the Sidr jQuery library in Rails?

I am utilizing a library named Sidr to generate sidebars. I have included all the necessary jQuery and CSS, and while it is operational, I find that I need to double click instead of just one click to open the sidebar. Here is the code snippet. I essentia ...

Miscalculation in PHP MySQL: Incorrect output when adding field 1 and multiplying field 2 by

In my MySQL table, there are 4 fields: product price cost, selling price, stock of products, and earnings per unit. For example: If the cost of our product is $100, we sell it for $120, and we have a stock of 10 units, the following code calculates the e ...

Arranging Check Boxes Side by Side

I am struggling to properly align the three checkboxes and tables next to each other. I have managed to get the checkboxes on the same row, but aligning them neatly has proven to be a challenge. Using Notepad++ as my development tool, I am facing formattin ...

Creating a slider directly under the header in an Ionic 3 application without any gaps

I need help with positioning a slider below the header within the ion-content. The issue is that I am experiencing unwanted white space on the top, left, and right sides, as depicted in the image. This is my HTML code for the slider: <ion-navbar colo ...

What could be causing the CSS border to not show up on the webpage?

I am trying to add a border to the footer, but it seems like something is blocking it from showing properly. Below are the CSS lines I have used: position: fixed; bottom: 0; right: 0; left: 0; clear: both; line-height: 1.36em; padding: 08px 0px 0px; tex ...

Animate div visibility with CSS transitions and Javascript

I'm currently working on incorporating an animation into a div that I am toggling between showing and hiding with a button click. While I have the desired animation, I am unsure of how to trigger it using JavaScript when the button is clicked. Can any ...

Searching and extracting HTML tags using DomCrawler

Trying to extract text content from HTML tags using the Symfony DomCrawler <html> <strong> This is a bold text </strong> <strong> This is another bold text </strong> <h2> This is header 2 text </h2> </htm ...

Integrating a PHP function within an ECHO statement

Here is a code snippet I'm currently using in my Wordpress: function wpstudio_doctype() { $content = '<!DOCTYPE html>' . "\n"; $content .= '<html ' . language_attributes() . '>'; echo apply_filte ...

Issue with Jekyll (seems like the stylesheet is missing?)

While attempting to fork a Jekyll theme and build the Github Page, I noticed that the generated page looks different from the original one I followed the instructions to change the baseurl in _config.yml, without making any other modifications. The only ...

The issue with the jQuery class change not being triggered in Internet Explorer seems to be isolated, as Chrome and

This little jQuery script I have is supposed to show a fixed navigation menu once the page has been scrolled below 200px, and then change the class on each menu list item to "current" when that section reaches the top of the viewport. The issue is that th ...