html - Animating the border in CSS -
i have navigation menu has border bottom 3 pixels has appearance similar of underline. have 2 animations in mind not sure how go including them. either have border fade 0.0 opacity 1 (full) opacity. or have border appear left right i.e. draw itself.
nav li:hover { border-bottom: 1px solid orange; padding-bottom: 3px; animation-name: navhover; animation-duration: 3.3s; } @-webkit-keyframes navhover { 1% { opacity: 0; } 100% { opacity: 1; } }
any answers appreciated! thank time.
i'd in case, want transitions, not animations. personally, if can use transition instead of animation, should use transition. use animations when can't want transition.
changing border colour on hover trivial:
.my-element { border-bottom: 1px solid transparent; transition: border-color 300ms; } .my-element:hover { border-color: orange; }
if want border animate 0 100% width, can't border. can use pseudoelement:
.my-element::after { content: " "; display: block; width: 0; height: 2px; background: orange; transition: width 300ms; } .my-element:hover::after { width: 100%; }
i've created demo can view here: https://jsfiddle.net/65pcelrp/
don't forget you'll want vendor-prefix transitions -webkit-transition
, -moz-transition
etc.
Comments
Post a Comment