markens
markens

Reputation: 113

css3 border-top appearing from the left on hover

What I'm trying to achieve is very simple, but I guess I don't understand how does it work. I want a border-top appearing from the left to the right, when in hover.

I tried few times unsuccesfully..It just appears but not the way I want. Last css I have is this one:

#navHead li {
  list-style: none;
  display: inline-block;
  margin-left: 1em;
}
.slideBorder {
  text-decoration: none;
  text-transform: uppercase;
  color: #7f7f7f;
  padding: 0.5em;
  border-top: 2px solid transparent;
  width: 0px;
  -webkit-transition: 1s ease;
  -moz-transition: 1s ease;
  -o-transition: 1s ease;
  o-transition: 1s ease;
}
.slideBorder:hover {
  border-top: 2px solid #1fda9a;
  width: 100%;
}
<ul id="navHead">
  <li><a class="slideBorder" href="#">hi</a>
  </li>
  <li><a class="slideBorder" href="#">hi</a>
  </li>
  <li><a class="slideBorder" href="#">hi</a>
  </li>
</ul>

Can anyone help me please?

Thanks

Upvotes: 1

Views: 37

Answers (1)

Paulie_D
Paulie_D

Reputation: 114991

You can't really animate a border like that but you could use a pseudo-element instead.

#navHead li {
  list-style: none;
  display: inline-block;
  margin-left: 1em;
}
.slideBorder {
  text-decoration: none;
  text-transform: uppercase;
  color: #7f7f7f;
  padding: 0.5em;
  position: relative;
}
.slideBorder:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: #f00;
  transition: width 0.5s ease;
}
.slideBorder:hover:after {
  width: 100%;
}
<ul id="navHead">
  <li><a class="slideBorder" href="#">hi</a>

  </li>
  <li><a class="slideBorder" href="#">hi</a>

  </li>
  <li><a class="slideBorder" href="#">hi</a>

  </li>
</ul>

Upvotes: 3

Related Questions