What is the method to maintain the underline effect in the demo with CSS?

As a CSS novice, I am curious to find out how to maintain the underline effect on links (as seen in this demo) without it disappearing when the mouse focus is removed. While I am aware that jQuery or javascript can be used to keep the focus on an element, I specifically want the underline to remain visible even after the cursor has moved away. Your help is greatly appreciated.

    <section class="blue-green">
    <nav id="cl-effect-4" class="cl-effect-4">
        <a id="focus-this" href="index.html">+ Create New</a>
        <a href="launch_approved.html">Launch Approved Campaigns</a>
        <a href="pending.html">Pending Approval</a>
        <a href="record.html">Your Campaign Record</a>
    </nav>
    </section>

Answer №1

If you want to trigger a hover event using JQuery when hovering over your anchor tags in order to apply a specific class, you can use the following code:

JQuery

$("a").hover(
  function () {
    $(this).addClass('highlight');
  }
);

Additional CSS

.highlight{border-bottom:3px solid red;}

Code Demo

Answer №2

To implement JQuery, try using this code:

 $("#focus-this").on({

 mouseenter: function () {
     $(this).focus(); },
 mouseleave: function () {
     $(this).blur(); }
});

You can find a demo here.

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

Exploring the Document Object Model to locate the adjacent sibling of a parent element

If I need to implement an event that hides the section .dependent-box whenever the element with class .radio-click-hide is clicked, what would be the best approach for traversing the elements to achieve this functionality? I have attempted the following co ...

How can I use jQuery to show an HTML dropdown menu populated from PHP?

Currently, I am working with a PHP backend that retrieves data from SQL. Specifically, it pulls a list of user ID numbers. I would like to showcase that list within an HTML select element using jQuery after a button is clicked. While contemplating how to ...

Mixing two elements for a continuous animation without the use of JavaScript

I'm interested in creating an animation that cycles between "0% interest free credit" and "free delivery". I am attempting to achieve this without the use of JavaScript, but so far I can only make the first element fade away without the second one fad ...

Styling a submission button with HTML and CSS

I've tried following a few solutions on Stack Overflow, but I just can't seem to get this simple line of code to work. <a class="lp-element lp-pom-button" id="lp-pom-button-25"><span class="label" style="margin-top: -10px;">Get Notif ...

What is the best way to bring in an external webpage using Jquery and Custom variables into an Iframe?

Is it possible to use JQuery to load a page into an iframe? I have a specific page that generates a custom printable PDF and I want it to be loaded into an iframe for user convenience. Since I utilize jQuery to fetch all the necessary variables, I cannot ...

determining the amount by which a div extends beyond the window's height

My challenge is to have a fixed div appear on top of various background images. The problem arises when this fixed div exceeds the height of the window, causing it not to scroll and resulting in lost content. I've attempted using max-height: 100% and ...

JavaScript Drag-and-Drop Statement Issues

Currently working on a JavaScript game that utilizes the drag and drop feature of HTML. The goal is to make randomly generated fruit images draggable and droppable onto a jelly image. When the dragged image matches a certain condition (e.g., when the numbe ...

How can I utilize the submitHandler in Form Validation to trigger the sending of 2 AJAX requests

While I have a solid grasp of php, html, and css, I am just starting to explore javascript and jQuery. The issue I'm encountering is related to a form on a page that needs validation before triggering two ajax requests. The first request should inser ...

Issue with retrieving body class in Internet Explorer on Magento platform. The body class is not being recognized in IE, but works fine in Mozilla and Chrome

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>" dir="ltr"> <?php echo $this->getChildHtml('head') ?> <bod ...

Angular4 validation for the full name input field is not functioning correctly as anticipated

I am currently working on creating a custom validator for a full name input field in an Angular 4 register form, but I am encountering some issues. The validator is displaying the "Only letters and spaces allowed" message even when the input only contains ...

Displaying a certain div when clicked within a loop using Vue.js and Laravel

I am currently facing an issue with displaying a hidden div upon click. The problem arises when using a loop to dynamically generate all the divs. Whenever I click the button, it shows all the divs instead of just one specific div on each click. I attempte ...

In Angular, what is the best way to change the format of the timestamp '2019-02-22T12:11:00Z' to 'DD/MM/YYYY HH:MM:SS'?

I am currently working on integrating the Clockify API. I have been able to retrieve all time entries from the API, which include the start and end times of tasks in the format 2019-02-22T12:11:00Z. My goal is to convert the above date format into DD/MM/Y ...

Is your 100% height not beginning at the top of the page?

The link provided showcases a tutorial that has a white column extending to the bottom of the browser. In this example, the white column begins from the very top, with a header in a different shade of grey covering it. In my scenario, I need the header to ...

When using the "top" property in position-absolute, the child element may exceed the boundaries of the parent element

My child element is overflowing its parent when I apply "top: random pixel" to it. It seems to be using the top position relative to the body of the page. // HTML <div class="movie-list"> <div class = "inn ...

The show/hide jquery function is functioning perfectly on desktop devices, but issues arise on mobile devices where the divs overlap each other when using the show() method

I need a way to toggle input text boxes based on selection using a select box This is the HTML code snippet: <div class="row"> <div class="form-group"> <div class="col-sm-1 label2"> <label class="control-label ...

Seeking assistance with a peculiar JSON parsing challenge

When making an ajax call and receiving what seems to be well-formed json, I encounter strange issues with parsing. Interestingly, it works fine on my development server but fails when the code is live online. The data retrieved from the ajax call looks li ...

Optimizing FileReader result for seamless compatibility on all browsers and devices when loading into an HTML5 video player

I want to implement a feature where the selected video file can be loaded into an HTML5 element for users to preview before sending it to the server. However, I am encountering an issue with compatibility on Chrome and Safari browsers, both on desktop and ...

Use the on-screen keyboard to move around by using the arrow keys and choose a value from the list to

I am currently working on developing an on-screen keyboard that allows for navigation using arrow keys and selection with the enter key. My goal is to have each selected key append to an input field. Below is the HTML code I have implemented: <div id ...

Adding material-ui library to a stylesheet

Can I include @material-ui/core/colors/deepOrange in my CSS file? I want to import this library and use it as shown below: import deepOrange from '@material-ui/core/colors/deepOrange'; import deepPurple from '@material-ui/core/colors/deepPu ...

Incorporate a redirect function following an alert using jQuery, AJAX,

Does anyone know how to implement a redirect after displaying an alert message once a form is submitted? $.ajax({ type: "post", data: person, async:false, url: 'https://webapp.example.c ...