HTML & CSS - Hover state maintained after transition
Simple example for StackOverflow
HTML
<div id="container">
<div id="content">Hover me !
<div class="tooltip">This is a tooltip</div>
</div>
</div>
CSS
/** The problem **/
.tooltip {
background-color: white;
border: 1px solid black;
padding: 10px;
opacity: 0;
transition: 1s 500ms;
transition-property: transform, opacity;
position: absolute;
right: 0;
top: 0;
}
#content:hover .tooltip {
display: block;
opacity: 1;
transform:translateX(100px);
-webkit-transform: translateX(100px);
}
#content {
transition: 1s 500ms;
transition-property: background-color, color;
cursor: pointer;
position: relative;
}
#content.active {
background-color: blue;
color: white;
}
#content.active .tooltip {
opacity: 0;
transform: none;
-webkit-transform: none;
}
/** Just for fun **/
html, body {
height: 100%;
overflow: hidden;
}
#container {
width: 80%;
height: 80%;
background: beige;
border: 1px solid black;
border-radius: 5px;
margin: 10px auto;
padding: 10px;
}
#content {
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 100px;
background: coral;
border: 1px solid black;
border-radius: 5px;
margin: 10px auto;
padding: 10px;
}
JavaScript
$( document ).ready(function() {
$('#content').click(function () {
$(this).toggleClass('active');
});
});