Style your list items with custom CSS for paragraph links

It's strange because the last time I tried to apply the same styling, it worked perfectly. However, now it's not working. Here is a snippet of my HTML:

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false><span><img src="test1.png"></span>TEST!<span class="caret"></span</a>
    <ul class="dropdown-menu">
        <a rel="nofollow" href="../test1"><li><p><img src="/assets/flags/test1.png"> Test1</p></li></a>
    </ul>
</li>

CSS:

.dropdown-menu > a > li > p {
    clear: both;
    line-height: 1.42857143;
    color: #555;
    white-space: nowrap;
    transition: color .2s ease;
}

.dropdown-menu > a:focus > li > p,
.dropdown-menu > a:hover > li > p {
    color: #ff7500 !important;
    text-decoration: none;
    transition: color .2s ease;
}

Thank you for your assistance, everyone! I really appreciate the support from the stackoverflow community!

Answer №1

Check out this solution

.dropdown-menu > li > a > p {
    clear: both;
    line-height: 1.42857143;
    color: #555;
    white-space: nowrap;
    transition: color .2s ease;
}

.dropdown-menu > li > a:focus > p,
.dropdown-menu > li > a:hover > p{
color:#ff7500  !important;
text-decoration: none;
transition: color .2s ease;
border: 1px solid #e6e6e6;
}

li {
  list-style-type: none;
}

a{
  text-decoration: none;
}
<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false>
    <span><img src="test1.png"></span>TEST!<span class="caret"></span></a>
    <ul class="dropdown-menu">
      <li><a rel="nofollow" href="../test1"><p><img src="/assets/flags/test1.png"> Test1</p></a></li>
    </ul>
</li>

Answer №2

Check out the updated HTML structure below for a more accurate representation:

<ul class="dropdown-menu">
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
      <span><img src="test1.png"></span>TEST!
      <span class="caret"></span>
    </a>
  </li>
  <li>
    <a rel="nofollow" href="../test1">
      <img src="/assets/flags/test1.png"> Test1
    </a>
  </li>
</ul>

View the updated fiddle here

The incorrect structure in your example was with the ul element, refer to the documentation here:

Docs :

https://developer.mozilla.org/en/docs/Web/HTML/Element/ul

Take note of the distinction between inline and block elements by referring to the following documentation:

Docs :

https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#Block-level_vs._inline

https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements

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

Loading message displayed in web browsers by banner rotation system

I'm currently working on a banner rotator function that seems to be showing a "loading" message continuously while running. Here is the code snippet for reference: var banners = ['../Graphics/adv/1.gif','../Graphics/adv/2.jpg']; / ...

Join together a pair of php variables

I am currently extracting text and color values from a form structured like this: Here are the codes in management.php: <form method="post" action=""> <input type="color" name="color"> <input type="text" name="text"> <input ...

Loading screen for specific content within the current WordPress theme

I am trying to display a preloader only in the 'content' div, but it ends up hiding the entire page. The structure of the site is as follows: Title Menu Content (where I want the preloader) Footer I'm having trouble figuring out where exa ...

Dynamic color change in SVG

I am facing an issue with changing the color of svg images in a menu list using the filter CSS property. Even though I have obtained the correct filter value from a library that converts hex to CSS filter, React seems unable to set this property on the ima ...

What is the best way to align this button directly below my paragraph?

I'm facing an issue with a tile on my website that flips over upon hovering. I tried adding a button on the back of the tile, but it ends up hanging off the bottom. I'm unsure of how to position it below the paragraph on the back of the tile. Add ...

Adjusting content alignment for mobile devices and centering on desktop screens

I am currently working on creating a responsive website and I have a specific layout in mind. I want to center some text and an image both vertically and horizontally within a div that has a minimum height, leaving plenty of blank space above and below the ...

Incorporating HTML elements within VBScript within a single document

Here is a code snippet that mixes VBScript and HTML: IF (x.name="name") THEN n=x.value response.write("<tr>") response.write("<th>Name:</th>") response.write("<td><input name=""n2"" value=" & n & ">< ...

What is the best way to include all the selected items from a multi-select list when updating my view model?

I am currently developing a website using ASP.Net Core 2.1 MVC. Within one of my views, I have implemented two multi-select lists to enable users to assign individuals to a site. The left-hand list displays all unassigned users, while the right-hand list ...

Display the div at the top - it doesn't seem to be functioning properly in the Chrome

My div has a z-index of 99999 and is displaying correctly on Firefox and Safari. However, when testing it on Chrome, the footer does not appear as the top element. What steps should I take to ensure it is the highest element? Do I need to make any additio ...

When utilizing Blazor to create dynamic URLs within a loop, incorrect references may be generated

While working on a Blazor web assembly application, I encountered an issue when trying to loop over content to generate URLs for MP3 files. The media files are named "1.mp3", "2.mp3", "3.mp3", and so on. Imagine having a razor page with the following con ...

Utilizing jQuery to apply a class to a targeted element when clicked

I'm currently working on animating a menu item where it expands to the left when hovered over, and contracts back when the mouse moves out. This part is functioning as expected. Additionally, I am trying to apply a specific color to the button by add ...

How can we extract validation data from a function using Ajax and then transfer that information to another Ajax query?

I have an AJAX function that validates a textbox on my page. After validating, I need to perform an action with that value (search in the database and display results in the textbox). However, I also need the validation function for another separate functi ...

Selecting options in combobox for each row in a table using Angular 2 programmatically

I am currently working on an Angular 2 application using TypeScript. In one of the tables within the application, there is a select control in one of the columns. The contents of this select control are bound to another string array. <table ngContr ...

Validation for radio buttons in Bootstrap 4

Looking for assistance with form validation using Radio elements on a Bootstrap 4 page. I want to display an error message underneath the radio element: <div class="invalid-feedback">Please choose an option</div> Below is the code snippet wi ...

When you click on a link, it will load on the same page with a

Recently, I integrated this jQuery template into my project. However, I noticed that whenever I click on specific links within the navbar, the URL shows something like index.php#page2.php. Can anyone explain what is causing this and how can I prevent it f ...

Unexpected results from Ajax post request: Success message returned as undefined

I have a situation where I am trying to post some data to a PHP file so that it can be saved in a database. My AJAX call appears to be working fine as I do receive an alert when the call is executed. However, the issue arises when my data does not seem to ...

Protecting a javascript string in php: A comprehensive guide

Having trouble with my PHP javascript string. Attempted to add a string to a variable within a switch statement but encountered an error: $blocPub = '<script type="text/javascript"> var rdads=new String(Math.random()).substring (2, 11 ...

You cannot select multiple values in Bootrap-Select

Inside my modal, I have input elements structured as follows: <div id="position_div" class="form-group row"> <label for="edit_jobs" class="col-4 col-form-label">Jobs</label> <div class="c ...

The issue with triggering button events in JavaScript

I've integrated a jquery modal popup for saving uploaded files related to a specific device. The modal appears, the cancel button functions correctly, but I am struggling to trigger the onclick event for the Save button... This is what I have impleme ...

Learn how to use fabric.js to layer a png image over a canvas and create a mask effect

https://i.sstatic.net/yT16J.png Is there a way to mask all canvas objects using a single layer? I have a png file that I want to use as a layer, which I load from a URL. What would be the best approach to achieve this? I have tried one method where I cli ...