Animated underline not showing once link is selected - css

I'm using Bootstrap and SCSS to customize my CSS file. I have a nav-link like this:
.sidebar .nav-pills .nav-link:hover,
.sidebar .nav-pills .show > .nav-link {
#extend %underline-link;
background: linear-gradient(120deg, $sidebar-navitem-background-color 65%, $sidebar-navitem-background-color 65%);
}
.sidebar .nav-pills .nav-link.active,
.sidebar .nav-pills .show > .nav-link {
#extend %underline-link;
background: linear-gradient(120deg, darken($sidebar-navitem-background-color, 2) 65%, darken($sidebar-navitem-background-color, 2) 65%);
}
%underline-link {
color: $underline-link-color;
position: relative;
text-decoration: none;
transition: all 0.4s ease;
&:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
bottom: 0px;
left: 0;
background: $underline-link-color;
visibility: hidden;
transform: scaleX(0);
transform-origin: center left;
transition: all 0.3s ease 0s;
}
&:hover {
transition: all 0.4s ease;
&:before {
visibility: visible;
transform: scaleX(1);
}
}
}
The line is animated as expected when hovering over the item. However, when the item is active, the line disappears.
How do I keep the line showing as long as the item is active?

As you want to make your active state the same as your hover state you need to add the :active pseudo class alongside your :hover pseudo class in your SCSS. That will ensure that when the user clicks the link (i.e. the link is active) the style remains the same. More information about active state on MDN.
I have created a codepen with different styles for hover and active to show the interaction happening. If :hover and :active have the same styles you would therefore see no difference between the two states.
&:hover,
&:active {
transition: all 0.4s ease;
&:before {
visibility: visible;
transform: scaleX(1);
}
}

Related

How to animate a link underline with border-bottom, so that there is space between the link text and the underline?

How could I animate the link underline with using border-bottom, so that there is space between the text and the underline?
I know how to do it in the following way, so that the default text-decoration element is animated. But I would like to have space between the link and the underline, that is why I think I need to use border-bottom. But I can't get the border-bottom work with the transition animation. How could I do this? I tried looking for other solutions, but couldn't find any. Thanks!
h2 > a {
position: relative;
color: #000;
text-decoration: none;
}
h2 > a:before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: #000;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
h2 > a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
you can fake an animated border via background and background-size:
a {
padding-bottom: 5px;
/* set here size + gap size from text */
background: linear-gradient(0deg, currentcolor, currentcolor) bottom center no-repeat;
background-size: 0px 3px;
transition: 0.5s;
text-decoration: none;
}
a:hover {
background-size: 100% 3px;
}
a[class] {
color: gray;
}
a.tst {
color: purple;
background: linear-gradient(0deg, currentcolor, currentcolor) bottom center no-repeat, linear-gradient(0deg, turquoise, turquoise) center calc(100% - 2px) no-repeat;
background-size: 0px 2px;
}
a.tst:hover {
background-size: 100% 2px;
}
<a href>kake animated border</a>
<a href class> why currentcolor ?</a>
<a href class="tst">mix of colors ?</a>
The code you've presented uses a pseudo-element not the default text-decoration. Since the pseudo element is positioned absolutely, you can change the distance easily. Change the a:before bottom to -5px or whatever negative value fits the distance that you want:
a {
position: relative;
color: #000;
text-decoration: none;
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: -5px;
left: 0;
background-color: #000;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
Long long text

Css button hover issue in chrome

I have faced a wired issue in chrome browser with button css. When I hover this button in chrome(not in firefox) its give unexpected effect.
here is current css:
input[type="button"], .button, button {
font-size: 100%;
transition: none !important;
text-transform: uppercase;
padding: 5px 15px;
line-height: 17px;
border-radius: 0px;
border: 3px solid #DDD;
background: transparent none repeat scroll 0% 0%;
color: #666;
font-weight: bold;
display: inline-block;
vertical-align: middle;
position: relative;
}
input[type="button"]:hover, .button:hover, button:hover {
border-color: #8E7EBF;
color: #FFF;
background: #8E7EBF none repeat scroll 0% 0%;
}
a, span, i {
-webkit-transition: all 0.25s ease;
transition: all 0.25s ease;
}
I think you must take a look on theses properties of CSS (line 1058 of theme.css) :
a:hover, span:hover, i:hover
You must used this synthax for better compatibility :
a:hover, button:hover span, button:hover i
You can see the similar problem here : Button:hover not working in Firefox
Hi Write this css in your css file it will fix the problem
a:hover, span:hover, i:hover {
-webkit-transition: initial;
transition: initial;
}
i had same issue on chrome on hover btn class i fixed that adding this class to button
.btn-reset-transform:hover {
-webkit-transition: none !important;
-moz-transition: none !important;
-ms-transition: none !important;
-o-transition: none !important;
transition: none !important;
-webkit-transform: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
-o-transform: none !important;
transform: none !important;
}

Apply transition for single pseudoclass

I want a transition on my button which should only be applied on hover but not on other pseudoclasses.
button {
width: 100px;
height: 50px;
color: white;
background-color: green;
transition: background-color 1s;
}
button:hover {
background-color: blue;
}
button:active {
background-color: red;
}
<button>Nice Button!</button>
So in this case I want it the transition from green to blue on hover but not from blue to red when active. How can I achieve it?
Set transition: none; on :active pseudo class + if you don't want a transition on mouseup, you can add
button:focus {
background-color: blue;
transition: none;
}
button {
width: 100px;
height: 50px;
color: white;
background-color: green;
transition: background-color 1s;
}
button:hover {
background-color: blue;
}
button:focus:hover {
background-color: blue;
transition: none;
}
button:active:hover {
background-color: red;
transition: none;
}
<button>Nice Button!</button>
I have to admit that your question is challenging !
My proposed solution:
button {
width: 100px;
height: 50px;
color: white;
background-color: green;
transition: background-color 2s;
}
button:hover {
background-color: blue;
}
button:active {
/* background-color: red; */
-webkit-animation: activate 0s 0s forwards;
animation: activate 0s 0s forwards;
}
#-webkit-keyframes activate {
0% {background-color: green;}
100% {background-color: red;}
}
#keyframes activate {
0% {background-color: green;}
100% {background-color: red;}
}
fiddle
The problem is that the base state is shared beteen the back transition from the hover and the activer pseudo classes, so I don'tthink this can be solved using only transitions.
The trick is not to change the color in the active state, it is still green inside, but it looks red :-)

CSS Fade in on hover

I'm currently attempting to have a with an image fade in when I hover over some text using CSS. I've applied the CSS code, but the effect doesn't show; the div appears, but without the fade-in.
Also, I realize that CSS transitions don't really work with IE. If anyone could point me in the right direction of a workaround for that, it would be much appreciated. (:
CSS:
.thumbnail{
position: relative;
z-index: 0;
}
.thumbnail:hover{
background-color: transparent;
z-index: 50;
}
.thumbnail span{ /*CSS for enlarged image*/
position: relative;
display: none;
color: black;
text-decoration: none;
opacity:0.0;
filter:alpha(opacity=0);
}
.thumbnail span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 5px;
left: -1000px;
border: 1px solid gray;
background-color: #fff;
}
.thumbnail:hover span{ /*CSS for enlarged image on hover*/
position: relative;
display: inline;
top: -290px;
left: -25px;
opacity:1.0;
filter:alpha(opacity=100);/*position where
enlarged image should offset horizontally */
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
#networking {
width: 200px;
height: 140px;
margin-left: 360px;
top: 115px;
position: absolute;
background-color: #613286;
opacity:1.0;
filter:alpha(opacity=100);
color: #ffffff;
text-align:center;
border-radius: 20px;
-webkit-transform: rotate(14deg);
-moz-transform: rotate(14deg);
-ms-transform: rotate(14deg);
-o-transform: rotate(14deg);
transform: rotate(14deg);
}
HTML:
<div id="networking">
<a class="thumbnail" href="1.5.2experientialstudios.html#down4"><h4>Networking Lounge</h4>
<span><img src="images/net3.jpg" width="250" /></span></a>
</div>
Thank you!
Try with removing your display rule:
.thumbnail span{ /*CSS for enlarged image*/
position: relative;
/*display: none; remove this */
color: black;
text-decoration: none;
opacity:0.0;
filter:alpha(opacity=0);
}
As you have opacity 0 you won't need display:none and you can't make a transition between not displayed at all to inlined as they are different types.
And modify this rule:
.thumbnail:hover span { /*CSS for enlarged image on hover*/
top: 0px; /* adjust as needed */
left: -25px;
opacity:1.0;
filter:alpha(opacity=100);/*position where
enlarged image should offset horizontally */
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
(the hover and then span can make it a bit jumpy).
I also added a ms prefixed version to transitions. It is apparently not useful in this context.
For IE9 and below you can use jQuery to fade in an element (or simply use vanilla JavaScript to modify the opacity in a setTimeout loop).
Fiddle here:
http://jsfiddle.net/AbdiasSoftware/9rCQv/
Is this what you're after?

Making CSS Image Rollovers Appear (vs. Slide in)

Not sure what's going on but I suspect jquery is at work... I am using an image sprite on hover, but the image slides in from the right as opposed to appear in place. See the blue bubble turn into a red bubble at http://www.maidinhoboken.com/testpage/
How do I get it to appear in place?
HTML:
<span class="displace">Test</span>
CSS:
a.rollover {
display: block;
width: 190px;
height: 190px;
text-decoration: none;
background: url(images/bubble_rollover1.png);
}
a.rollover:hover {
background-position: -190px 0;
}
.displace {
position: absolute;
left: -5000px;
}
Add this to your CSS file on line 1666
a.rollover, a.rollover:hover {
transition: none;
-moz-transition: none;
-webkit-transition: none;
-o-transition: none;
-ms-transition: none;
}
You have a transition set somewhere in your style sheet that is being inherited.
You have CSS transition which makes the image roll instead of appear. Put transition:none rule into a.rollover:
a.rollover {
display: block;
width: 190px;
height: 190px;
text-decoration: none;
background: url(images/bubble_rollover1.png);
/* add this */
transition: none;
-moz-transition: none; /* Firefox 4 */
-webkit-transition: none; /* Safari and Chrome */
-o-transition: none; /* Opera */
}
You have transitions set on the links here
a, a:visited {
color: #3FB6D7;
text-decoration: none;
transition: all 0.2s ease-in-out 0s;
}
remove it and it should be fine

Resources