MasterDex
MasterDex

Reputation: 303

Sliding border from right to left using CSS

I have a header that I want to have a border on that slides from right to left on hover, using pure CSS if that's possible.

At the moment, I can get a border that slides from left to right using the following CSS:

#header a:after {
content: '';
display: block;
border-bottom: 3px solid $(header.hover.color);
width: 0;
-webkit-transition: 1s ease;
        transition: 1s ease;
}

#header a:hover:after { width: 100%; }

Has anyone a good solution for accomplishing this task?

Upvotes: 12

Views: 32452

Answers (2)

Bogdan Kuštan
Bogdan Kuštan

Reputation: 5577

You can position your :after element to the right

#header {
  position: relative;
}
#header a:after {
  content: '';
  display: block;
  border-bottom: 3px solid red;
  width: 0;
  position: absolute;
  right: 0;
  -webkit-transition: 1s ease;
  transition: 1s ease;
}

#header a:hover:after { 
  width: 100%; 
}

Upvotes: 26

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167182

Give all:

-webkit-transition: 1s all ease;
        transition: 1s all ease;

Upvotes: 1

Related Questions