Tips for modifying the color of the last anchor in a list item

li elements are utilized to create breadcrumb in a shopping cart. The breadcrumb displays all anchor elements using the style defined for an 'a' element from site.css. How can I make the last anchor's color black?

I attempted the style below. The background color only appears when the mouse is over the element. How do I make the link text black even when the mouse is not hovering over it?

The jquery jBreadCrumb from is used to convert the list into a breadcrumb. jQuery, jQuery-UI, and ASP.NET MVC2 are also being used.

HTML:

<div id="breadCrumb" class="breadCrumb module">
<div style="overflow:hidden; position:relative; width: 990px;">
<div>
<ul style="width: 5000px;">
<li class="first">
<a href="/"></a>
</li>
<li>
<a href="/Store/Category?category=1">Level1</a>
</li>
<li>
<a href="/Store/Category?category=28">level2</a>
</li>
<li class="last">
<a href="/Store/Browse?category=37521"
style="color:black">level3shouldbeblack</a>
</li>
</ul>
</div>
</div>
</div>

CSS:

.breadCrumb ul li.last, .last, .last:hover, .last:link, .last:visited, 
    .last:active {
    color:Black !important;
}

Update

I added li:last-child, but the problem still persists. Below is the content from the FireBug Style tab. For some unknown reason, the black color only appears when the mouse hovers over the last anchor text. How can I make sure the last anchor text is always black?

.breadCrumb ul li a {
    display: block;
    float: left;
    height: 21px;
    line-height: 21px;
    overflow: hidden;
    position: relative;
}
a:link, a:visited {
    text-decoration: none;
}
.breadCrumb ul li.last, .last, .last:hover, .last:link, .last:visited, .last:active {
    color: Black !important;
}
.breadCrumb ul li {
    font-size: 0.9167em;
    line-height: 21px;
}
li:last-child {
    color: Black !important;
}
.breadCrumb ul li.last, .last, .last:hover, .last:link, .last:visited, .last:active {
    color: Black !important;
}
body {
    font-family: Helvetica,Arial,sans-serif;
}

Answer №1

If you want to modify the color of the link in the final item on the list, you can do so by using this code:

.final-item a{
    color: black;
}

An alternative approach is to utilize the :last-child selector as shown below:

li:last-child a {
    color: black;
}

Answer №3

Have you thought about implementing a highlighted CSS class and applying it to the final breadcrumb element using jQuery upon page load?

.highlighted a { color: black; }

<script type="text/javascript">
    $(function () {
        $("li:last", $("#breadCrumb")).addClass("highlighted");
    });
</script>

Answer №4

Implement the :last-child selector

ul:last-child
{
 font-size:16px !important;
}

Answer №5

Set the color of the last link in a list to black using either "li.last a{color : black;}" or "li:last-child a{color : black;}".

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

Filtering option exclusive for body rows in the table

I'm looking to customize this filter to specifically target <tbody> rows in my table and display only the thead rows as the output. $("#searchInput").keyup(function() { var rows = $("#AR").find("tr").hide(); var data = this.value.split( ...

Switch the CSS class with an HTML tag

Can someone help me transform this code snippet with Python 3 and Beautiful Soup? <span class="ld-nowrap"> 20th century’s </span> I need to convert it to: <em> 20th century’s </em> Any suggestions on how to achieve t ...

How can I adjust the size of posts on the Tumblr Official Theme?

The size of posts on the Tumblr Official Theme caught my attention recently. It seems they are set at 500px, causing photos posted on the blog at the original dash post size of 540px to be compressed. I've examined the coding for the theme but can&apo ...

Issue with form action redirection on Node JS Express server not functioning correctly

My EJS application involves using jQuery in the JavaScript code to fetch JSON data from the Google Custom Search API. The app then uses the GET method to navigate to /search, passing the query as the attribute for q. Here's an example of the form&apos ...

AngularJS: Handling Click Events

I am just getting started with AngularJS. Recently, I came across a situation where I had a PHP script that returned data in JSON format. To handle this response, I utilized the following code: <div ng-app="myApp" ng-controller="gameCtrl"> < ...

Can a specific CSS rule be written in Material UI using makeStyles that will only apply if the element has both classes together?

It's common knowledge that achieving this in CSS is a possibility. .makeStyles-mainNavWrapper-67.sticky{ position: fixed; top: 0px; opacity: 1; transition: opacity 1s ease; padding: 10px; } I am curious to find out if this can be achieved ...

Incorporating a CSS Module into a conditional statement

Consider the following HTML structure <div className={ `${style.cell} ${cell === Player.Black ? "black" : cell === Player.White ? "white" : ""}`} key={colIndex}/> Along with the associated CSS styles .cell { ...

Incorporating Google's Invisible Recaptcha with Jquery Ajax and PHP

I am struggling to make my form, which includes Google invisible reCAPTCHA, work seamlessly with my jQuery AJAX and PHP. It appears that the token is not being properly sent to my PHP page via AJAX, resulting in the following error message from my PHP scri ...

Laravel: Input information into a form containing multiple dropdown menus

I am in search of a Laravel or HTML example that demonstrates filling out a form with multiple drop-down lists. Here's my scenario: I have the following text inputs: name_customer, phone_customer, email_customer. I want the form fields to automatical ...

I am having trouble getting my HTML to properly link with my CSS while using Chrome OS

My website code is not linking with the CSS file <!DOCTYPE html> <html> <head> <link href="main.css" rel="slylesheet" text="text/css"> <title></title> </head> <body> < ...

Styling is applied by Bootstrap to inputs in a form that are not required

I am currently working on validating a form for empty fields using Bootstrap. When submitting and validating the form with the form.checkValidity() method, I noticed that even the non-required fields are being styled as if they are required. Is this normal ...

Choosing a hyperlink within a cell depending on the surrounding text in that cell

Attempting to pick out the hyperlink text from a table cell when the desired text is also present in the cell Following an answer in that discussion, I have reached this point with my query. This is my current progress: def click_me(myString): WebDr ...

What is the best approach for testing an HTML element that does not have distinct attributes?

Currently, I am utilizing Coded UI Test to conduct tests on a web application. In my workflow, I rely on a class called Locator to store specific information necessary for CUIT to locate a control. When it comes to interacting with a control, a page objec ...

Creating interactive JavaScript elements that can be moved around within a container

I recently faced a challenge while attempting to make draggable elements within a div. The issue arose when I realized that I couldn't figure out how to drag each element individually without affecting the others. My current code only allows for handl ...

After pressing the login button, my intention is to transition to a different page

I am relatively new to web development and working with angular. I have a login component that, upon hitting the LOGIN button, should redirect to another component on a different page. However, currently, when I click the button, it loads the data of the o ...

execute a separate function within an ajax request callback

I've created a function to validate usernames on my website. //Custom username validation function $('#username').blur(function() { var v=this.value; if(v == "") { addErrorMessage(this,'This field ...

Preventing Button Click with JQuery Tooltip

I've implemented a JQuery tooltip plugin on my website and it's working great. However, I'm facing an issue where I cannot click on the input button that appears when hovering over the tooltip. It seems like the button is not truly part of t ...

Styling not taking effect in fancybox for a specific plugin

I have integrated the Yii tokeninput plugin for autocomplete functionality on my website. Interestingly, I noticed that when the plugin is used on a regular page, the CSS is applied correctly. However, if it is used within a fancybox, the CSS does not seem ...

pass user identification by using a link using php and MySQL

In my table of items, there is an option for users to delete or restore each item, using a special PHP file called 'delete.php'. print "<td>"; if ($row['deleted'] == 'y') { print "<a href='delete.php?id=2'& ...

Adjusting the repeating-linear-gradient CSS background

My goal is to make adjustments to a specific CSS code, in this case it is the repeating-linear-gradient. Take a look at my current implementation: input[type="range"]::-moz-range-track { background: repeating-linear-gradient(to right, #ccc, # ...