Sizing sliding underline - html

I want to make the sliding underline to run from left to right when i hover, and also set up the width of the line from the 1st letter to the last, and not bigger. How can i do that?
.nav-bar a:hover {
color: #000;
}
.nav-bar a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
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;
}
.nav-bar a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
<div class="nav-bar">
<ul>
<li>RETROSPECTIVE SHOW /2006/</li>
<li>TEXTS</li>
<li>BIBLOGRAPHY</li>
</ul>
</div>

You can use display: inline-block; to keep the fixed width. And for underlining you can use pseudo-classes like :before and :after.
Have a look at the snippet below:
/* LEFT TO RIGHT */
.sliding-left-to-right {
display: inline-block;
margin: 0;
}
.sliding-left-to-right:after {
content: '';
display: block;
height: 3px;
width: 0;
background: transparent;
transition: width .5s ease, background-color .5s ease;
}
.sliding-left-to-right:hover:after {
width: 100%;
background: blue;
}
/* LAYOUT STYLING */
body {
margin: 20px;
}
a {
text-decoration: none;
font-size: 20px;
font-weight: bold;
color: blue;
}
a:hover {
color: blue;
text-decoration: none;
cursor: pointer;
}
<a class="sliding-left-to-right">Underline – Left to Right</a>
Hope this helps!

Related

Hover link border animation

I would like to know how to animate the link when I hover on it. I want the top border to move down and the bottom border to move up. The borders should fade away, when the animation ends. When I hover on the link, the borders should appear and show the animation.
HTML:
<ul>
<li class="active">Home</li>
<li>About Me</li>
<li>My Passion</li>
</ul>
CSS:
ul li a {
border-bottom: 3px transparent solid;
border-top: 3px transparent solid;
}
ul li a::before {
position: absolute;
left: 0;
top: 0;
visibility: hidden;
-moz-transition: 0.3s;
-o-transition: 0.3s;
-webkit-transition: 0.3s;
transition: 0.3s;
}
ul li a::after {
position: absolute;
left: 0;
top: 100%;
visibility: hidden;
-moz-transition: 0.3s;
-o-transition: 0.3s;
-webkit-transition: 0.3s;
transition: 0.3s;
}
ul li a:hover {
color: blue;
}
ul li a:hover::before {
visibility: visible;
top: 100%;
background: blue;
}
ul li a:hover::after {
visibility: visible;
top: 0;
background: blue;
}
Expected result:
I've re-created the example in your GIF.
For the text hover effect, make sure to use transition to ease the effect, e.g.:
a {
color: white;
text-decoration: none;
transition: 800ms ease color;
display: block;
}
a:hover {
color: gold;
}
I'm displaying the a tag as block to make sure it covers the whole li elements when hovered.
When using CSS pseudo elements always set a content property (content: '' is you want to style it):
li::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 5px;
background: gold;
opacity: 0;
}
Instead of using a border, I'm animating the pseudo before en after elements on hover. You can do this by using CSS keyframes.
li:hover::before {
opacity: 1;
animation: flyDown 300ms ease forwards;
}
li:hover::after {
opacity: 1;
animation: flyUp 300ms ease forwards;
}
#keyframes flyDown {
from {
transform: translateY(0px)
}
to {
transform: translateY(90px)
}
}
#keyframes flyUp {
from {
transform: translateY(00px)
}
to {
transform: translateY(-90px)
}
}
Please find jsfiddle here: https://jsfiddle.net/sanderdebr/fn4pgwv6/30/
---html---
<span class="a-border" onclick="menuclick(this)">ABOUT US</span>
<span class="a-border" onclick="menuclick(this)">CREATERS</span>
<span class="a-border" onclick="menuclick(this)">NEWS</span>
<span class="a-border" onclick="menuclick(this)">CONTACT</span>
---css---
a {
text-decoration: none;
}
a:hover {
cursor: pointer;
}
.a-border {
display: inline-block;
position: relative;
color: white;
padding: 0.5rem 0.25rem;
margin: 0 1.5rem;
overflow: hidden;
}
.a-border::after {
content: "";
display: block;
position: absolute;
bottom: -8px;
left: -3%;
width: 106%
border-top: 2px solid white;
transform: scale(0, 1);
transform-origin: 0% 100%;
transition: transform 0.4s;
}
a:hover .a-border::after {
transform:scale(1, 1);
}
a.focused .a-border::after {
transform: none;
}
---js---
function menuclick(underline) {
var focused = document.getElementsByClassName("focused");
var i;
for (i = 0; i < focused.length; i++) {
var under = focused[i];
if (under.classList.contains('focused')) {
under.classList.remove('focused');
}
}
if (!underline.parentElement.classList.contains('focused')) {
underline.parentElement.classList.add('focused');
}
}

Underline CSS link mobile width

I have this css code and it works fine on large desktops. Once i switch to mobile the underline is under the whole element. I would like to have the underline only under the words in sentence.
Any help to achive this will be welcomed.
Here is the HTML:
a class="underline-link"
href="#">Made with Lorem Ipsum Dolor Sit Amed
And here is the CSS:
.underline-link:after {
background-color: #0982ae
}
.underline-link:hover {
color: #0982ae
}
.underline-link:after {
content: "";
height: 1px;
left: 0;
opacity: 0;
pointer-events: none;
position: absolute;
top: 100%;
transform: translateY(1px);
transition: all .15s cubic-bezier(.39, .575, .565, 1);
transition-property: opacity, transform;
width: 100%
}
.underline-link:focus {
outline: none
}
.underline-link {
font-family: -apple-system, BlinkMacSystemFont, segoe ui, avenir next,
avenir, helvetica neue, helvetica, ubuntu, roboto, noto, arial, sans-serif;
-webkit-font-smoothing: subpixel-antialiased;
text-decoration: underline;
color: #b3b3b3;
cursor: pointer;
position: relative;
display: inline-block;
color: #087096;
font-size: 14px;
font-weight: 400;
text-decoration: none;
-moz-osx-font-smoothing: grayscale
}
.underline-link:hover {
text-decoration: none
}
.underline-link:focus:after, .underline-link:hover:after {
opacity: 1;
transition-delay: .2s;
transition-duration: .15s;
transform: translateY(-3px) translateZ(0)
}
Live preview:On Codepen
Ok i found the issue, it's about position: absolute;
you can check the line position if you change bottom: 0; to top: 0;
i've to think how to trick over it and if there's some way to solve it, at the moment i don't have any solution on mind.
h2 > a {
position: relative;
color: #000;
line-height:50px;
text-decoration: none;
}
h2 > a:hover {
color: #000;
}
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);
}
h2 > a >span {
position: relative;
color: #000;
text-decoration: none;
}
h2 > a >span:hover {
color: #000;
}
h2 > a > span:before {
content: "";
position: absolute;
width: 100%;
height: 2px;
top: 40;
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 > span:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
<h2><a><span>Look at this large truncated text effect with css, it's magic! </span></a></h2>
i tried with adding a span and setting the same but on top but i can't get rid on how moove this line, it keeps up due to display and positions so... i think this, as you thinked, can't work, sorry.

CSS underline animation causes flicker in safari, found solution but caused blurry text

As stated, only in safari, my CSS underline animation causes the rest of the nav bar to the right of hover to flicker. Putting -webkit-transform:translate3d(0,0,0); in the header section solves flicker, but makes text all blurry. Any solution to the blur? Below is CSS and HTML text that should be able to re build the issue
header {
background-color: #f5f5f5;
webkit-transform: translate3d(0, 0, 0);
text-align: center;
padding: 20px 0 0 0;
}
.wrapper {
width: 1280px;
margin-left: auto;
margin-right: auto;
background-color: #EBE8E8;
}
nav a {
color: white;
font-family: 'arimo', sans-serif;
text-decoration: none;
position: relative;
}
nav a:before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: white;
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;
}
nav a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
nav {
margin: 30px 0 0 0;
padding: 20px 0 20px 0;
background-color: #1764b0;
}
nav a {
padding: 25px 30px 5px;
text-decoration: none;
}
<html>
<head>
<link href="/test/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<nav>HOMER-WORLDLINEUPCONTACT
</nav>
</header>
</body>
</html>
Well you're <body> tag is placed above your <head> tag, so I guess that would be your issue. Also in the future, you're best working within codepen for this type of thing. I've gone ahead and added your code to an anonymous pen:
https://codepen.io/anon/pen/NyMOwd
Try this:
https://codepen.io/anon/pen/wyjQqm
nav > a:before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: white;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
nav > a:hover:before,
nav > a:focus:before {
visibility: visible;
transform: scaleX(1);
}
Remove the translate prop from the header and add the following props to nav a::before
backface-visibility: hidden;
font-smoothing: antialiased;
Hope this helps.

How to keep active menu item underlined?

I'm really new to HTML and CSS. I have a navbar which underlines the menu item you hover with a fade in, fade out-effect from the middle,
but how can I keep an active menu item underlined with the same style?
I'm also using Typo3 / Fluid which creates me the html code and assigns the "active" class to the active menu item.
This is how it looks like so far: https://jsfiddle.net/wr5w09r0/
css
div#top_nav{
text-align: center;
}
div#top_nav li{
display: inline;
padding: 15px;
}
div#top_nav a {
display: inline-block;
position: relative;
}
div#top_nav a:hover{
color: orange;
}
div#top_nav a:before{
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: -3px;
left: 0;
background-color: orange;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.15s ease-in-out 0s;
transition: all 0.15s ease-in-out 0s;
}
div#top_nav a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.active {
color: orange;
}
Hope this will help you. I have added this simple element.
div#top_nav a:hover:before , div#top_nav a.active:before
a {
text-decoration: none;
}
div#top_nav{
text-align: center;
}
div#top_nav li{
display: inline;
padding: 15px;
}
div#top_nav a {
display: inline-block;
position: relative;
}
div#top_nav a:hover{
color: orange;
}
div#top_nav a:before{
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: -3px;
left: 0;
background-color: orange;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.15s ease-in-out 0s;
transition: all 0.15s ease-in-out 0s;
}
div#top_nav a:hover:before , div#top_nav a.active:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.active {
color: orange;
}
<div id="top_nav">
<ul>
<li class="mainMenu-itemLevel1">
seite1</li>
<li class="mainMenu-itemLevel1">
seite2
</li><li class="mainMenu-itemLevel1">
seite3</li>
<li class="mainMenu-itemLevel1">
seite4</li>
<li class="mainMenu-itemLevel1">
Seite5 lang Hover</li>
</ul>
</div>
Hope this will help you.
You need to use javascript to do this.
Your javascript would add a class, like active to the relevant menu item, and you can then use your css to style it appropriately.
After adding the active class to the element, to apply your orange style use this:
div#top_nav.active a{
color: orange;
}
Note the addition of .active which selects only active items, and the omission of :hover on the link, since you no longer care about hover.
You may find the , css operator useful here, for applying the same styles to different selectors (active, and hover) as shown in my example below:
var items = document.getElementsByClassName('item');
var activeClassName = 'active';
function unselectItems() {
for (var i = 0; i < items.length; i++) {
items[i].classList.remove(activeClassName);
}
}
function selectItem(item) {
unselectItems();
item.classList.add(activeClassName);
}
function onItemClick(event) {
selectItem(event.target);
}
for (var i = 0; i < items.length; i++) {
items[i].addEventListener('click', onItemClick);
}
span {
border: 1px solid black;
padding: 5px;
}
span:hover, span.active {
color: white;
background-color: black;
}
<nav>
<span class="item">Home</span>
<span class="item">About</span>
<span class="item">Contact</span>
<nav>

Trying to get underline to start relative to the nav menu item in SCSS

I'm trying to implement a menu nav bar that on hover highlights the menu item with an underline animation from LEFT to RIGHT.
Currently I have the underline animating from the center of the menu item to the outside.
I have tried searchng for a solution to this but can't figure out what I'm doing wrong.
Here is a link to the project on codepen http://codepen.io/anon/pen/JowgqP
HTML
<menu>
<p><strong>Home</strong>
<strong>About</strong>
<strong>Portfolio</strong>
<strong>Contact</strong> <strong>
<p class="note">This is a recreation of the link hover effect from factmag.com</small>
</menu>
CSS (SCSS)
#import url(http://fonts.googleapis.com/css?family=Noto+Serif:400,700,400italic);
$link-color: #E71818;
$text-color: black;
$article-font: Noto serif, serif;
menu {
color: $text-color;
font-family: $article-font;
max-width: 30em;
}
p {
font-size: 18px;
line-height: 1.5;
}
menu a {
#extend %fancy-link;
}
.note {
display: inline-block;
border-top: 1px solid $link-color;
color: #777;
font-size: .8em;
font-style: italic;
margin-top: 2em;
padding-top: 1em;
}
%fancy-link {
color: $link-color;
position: relative;
text-decoration: none;
transition: all 0.15s ease-out;
&:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0px;
left: 0;
background: #f00;
visibility: hidden;
transform: scaleX(0);
transition: all 0.3s ease-in-out 0s;
}
&:hover {
transition: all 0.15s ease-out;
&:before {
visibility: visible;
transform: scaleX(1);
}
}
}
The default transformation point is center center...or rather 50% 50% for ease of reference. (For 2 dimensions...we'll leave out z offsets for now.)
You would have to amend this so that the origin is now center left
&:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0px;
left: 0;
background: #f00;
visibility: hidden;
transform: scaleX(0);
transform-origin: center left; /* here */
transition: all 0.3s ease-in-out 0s;
}
Codepen Demo
Transform-Origin # MDN