Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sliding border from right to left using CSS

Tags:

html

css

sliding

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?

like image 849
MasterDex Avatar asked Jul 02 '15 09:07

MasterDex


People also ask

How do you put a border on one side in CSS?

If you want to set a border to just one side of the element, use four values (write none to the side you want no border to appear). If you want to set a border to the top and bottom sides, use two values (write none to the second value).

How do you change the border in CSS?

Set the container div to position: relative and then absolutely position the new inner div to the edges of the container like so: position: absolute; top: 0; bottom: 0; left: 0; right: 0; . Then you can animate the border of the inner div while the content still sits within the container div free of the transform.


2 Answers

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%; 
}
like image 162
Bogdan Kuštan Avatar answered Sep 28 '22 08:09

Bogdan Kuštan


Give all:

-webkit-transition: 1s all ease;
        transition: 1s all ease;
like image 42
Praveen Kumar Purushothaman Avatar answered Sep 28 '22 07:09

Praveen Kumar Purushothaman