Make sure to maintain the hover effect even after clicking

How can I make my div retain the hover effect even after clicking on it? Here is the code snippet:

#work_btn{
position:absolute;
top:60%;
left:60px;
color:grey;
background: -webkit-linear-gradient(0deg, #ff956c, #ff3644);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
text-align:left;
z-index:20;
}


#blank_work{
position:absolute;
width: 80px;
height: 100px;
margin-top:100px;
background:red;
-webkit-transition:all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
-moz-transition:all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
transition:all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
}



.button_cadre_work:hover #blank_work{
margin-top:100px;
margin-left:80px;
}
<a href="#"><div class="button_cadre_work"><div id="work_btn">WORKS</div>
  <div id="blank_work"></div>
  </div></a>

Answer №1

To implement the functionality of toggling a class upon clicking a link, you would need to utilize javascript.

Once the class has been toggled, you can style the link with the active class in the same manner as you would for hover effects.

For reference, check out this fiddle: http://jsfiddle.net/s81yo6s5/

The following javascript code snippet can be used to toggle an is-active class on the .button_cadre_work element:

var button = document.querySelector(".button_cadre_work");

button.addEventListener("click", function(e) {
   this.classList.toggle("is-active"); 
});

After toggling the class, you can style it similarly to how you would for hover states:

.button_cadre_work:hover #blank_work,
.button_cadre_work.is-active #blank_work {
    margin-top:100px;
    margin-left:80px;
}

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

Navigating React Router: Updating the page on back button press

Looking for a solution to a persistent issue. Despite various attempts and exhaustive research, the problem remains unresolved. Here's the situation: Within my React-Router-Dom setup, there is a parent component featuring a logo that remains fixed an ...

Updating the CSS link href in ASP.NET using code behind

I'm struggling with changing the CSS href in the code-behind of my .ASPX page. I've tried various methods but haven't found a solution that works as intended. HTML Markup: <link id="linkCSS" runat="server" href='/css/1.css' re ...

Difficulties arise when trying to align text vertically between two floating images

After running the code, I noticed that the text "Text Here" is positioned at the bottom of the div instead of the top. I have attempted to adjust it using properties like vertical-align, padding, and margin-top within the .subText styling, but so far, I ha ...

Interactive Table - Enhance Your Searching Experience with jQuery

Recently, I've been tackling a Live Search solution for my data table. Success! When searching for Jim, everything works flawlessly. ...

CSS: The Drop Down menu suddenly vanishes every time I attempt to select an item from the visible list

I'm facing an issue with my dropdown menu that I can't seem to resolve. Whenever I hover over the menu, it disappears before I can even click on any items. <ul id="menu"> <li><a href="#title">Home</a></li> ...

Issues with the menu pop-up functionality arise when utilizing the CSS class .active

When I have this code, the ".active" function doesn't work when clicked. However, if I change the div class from "top-menu-popup" to "top-menu-popup active" when opening the page, the menu is already activated. <div class="top-menu-popup"> ...

The container or row I placed in the middle of the page content is not anchored to the bottom like it should be for footer widgets

I'm struggling with the code I've extracted. How can I move the footer widget to the bottom of the page? On some pages, the footer displays at the bottom because there isn't much content, but on one specific page, it appears in the middle of ...

Troubleshooting CSS issues in HTML pages

I created an HTML file but the CSS properties are not displaying correctly in the browser. I'm not sure where I made a mistake. Instead of using a separate CSS file, I have included it directly in the HTML file. <!DOCTYPE html> <html> &l ...

Learn to Generate a Mathematical Quiz with Javascript

For a school project, I am tasked with developing a Math Quiz which showcases questions one at a time. The questions vary in type, including Multiple Choice, Narrative Response, Image Selection, Fill in the blank, and more. I require assistance in creatin ...

When I expand the accordion next to it, the accordion disappears, and it also vanishes when I close that accordion

After incorporating accordions into my site, I encountered a peculiar issue (as shown in this video): when I open one accordion, the adjacent accordion also opens unexpectedly. Similarly, closing one accordion causes its neighboring accordion to mysterious ...

How to Align Item at Center in Bootstrap 5 Jumbotron

My jumbotron contains the bx-message-error icon that I want to center both horizontally and vertically in a row. Despite searching online and going through the documentation, I haven't been able to align it. I'm sure it's a simple fix, so an ...

Enhancing nouislider jQuery slider with tick marks

I have integrated the noUIslider plugin () into one of my projects. I am seeking guidance on how to display tick marks below each value on the slider. This is the current initialization code for the slider: $slider.noUiSlider({ 'start': sta ...

JavaScript Event Listener not Working Properly

I've been attempting to implement a feature on my website where the header hides when scrolling down and re-appears when scrolling up. However, I'm struggling to make use of the code snippet below to achieve this functionality. Despite my thoroug ...

What is the best way to format this <li> element so that the second line of text starts directly below the beginning of the first line, rather than below the bullet point itself?

Is there a way to align the second row of a list item directly below the text and not below the bullet point? <ul class="arrow-list"> <li>Clear and consistent brand identity</li> <li>+47.08% Increase in website registration ...

Problem with keyframe animations in Internet Explorer 10

My CSS animation works flawlessly in all modern browsers, except for IE10 which is causing some trouble. It appears that IE is having difficulty properly rotating 360deg. I am still searching for a workaround that won't compromise the functionality in ...

CSS - vertical and horizontal lines vary in thickness depending on the design

I am working on creating a grid that is automatically generated in my Angular 2 application. Currently, it consists of 1px wide divs as vertical lines and 1px high divs as horizontal lines. However, there seems to be an issue with inconsistent thickness be ...

jQuery's capability to select multiple elements simultaneously appears to be malfunctioning

I am dynamically creating div elements with unique ids and adding span elements with specific CSS properties. $(".main").append("<div class=largeBox id=" + counter + "</div>"); $(".largeBox").append("<span class=mainTitle></span>"); ...

Creating a container that matches the dimensions of its neighboring container without using relative or absolute positioning

I am seeking a solution to make the ".on-the-left" container have the same size as the ".on-the-right" container, but without relying on relative or absolute positioning. Here is the visual outcome I am aiming for: https://jsfiddle.net/NicoZZZ/osbL16z9/28 ...

Navigation Menu Dropdown Present on the Right Side and Arranged in a Horizontal Stack

I'm having trouble with a dropdown menu in my navigation bar. I followed the example on W3Schools but when I hover, the menu appears horizontally instead of vertically and to the far right of the page. I've searched for solutions but can't s ...

Utilizing /deep/ and the triple greater than symbol (>>>) within Angular 2

After researching the /deep/ and ::shadow selectors, I've come across conflicting information. In a discussion on Stack Overflow: What do /deep/ and ::shadow mean in a CSS selector? It was noted that Chrome has deprecated the /deep/ combinator and i ...