滑动按钮

101 阅读1分钟

CSS

body{
    background: #2c3e50;
}
nav{
    position:relative;
    margin: 270px auto 0;
    width: 590px;
    height: 50px;
    background: #34495e;
    border-radius: 8px;
    font-size: 0;
    box-shadow: 0 2px 3px 0 rgba(0,0,0,.1);
}
nav a{
    font-size: 15px;
    text-transform: uppercase;
    color: white;
    text-decoration: none;
    line-height: 50px;
    position: relative;
    z-index: 1;
    display: inline-block;
    text-align: center;
}
nav .animation{
    position: absolute;
    height: 100%;
    top: 0;
    z-index: 0;
    background: #1abc9c;
    width: 100px;
    border-radius: 8px;
}
a:nth-child(1){
    width: 100px;
}
nav .start-home, a:nth-child(1):hover~.animation{
    width: 100px;
    left: 0;
    transition: all .5s ease;
}
a:nth-child(2){
    width: 110px;
}
nav .start-about, a:nth-child(2):hover~.animation{
    width: 110px;
    left: 100px;
    transition: all .5s ease;
}
a:nth-child(3){
    width: 100px;
}
nav .start-blog, a:nth-child(3):hover~.animation{
    width: 100px;
    left: 210px;
    transition: all .5s ease;
}
a:nth-child(4){
    width: 160px;
}
nav .start-protfolio, a:nth-child(4):hover~.animation{
    width: 160px;
    left: 310px;
    transition: all .5s ease;
}
a:nth-child(5){
    width: 120px;
}
nav .start-contact, a:nth-child(5):hover~.animation{
    width: 120px;
    left: 470px;
    transition: all .5s ease;
}

html

<nav>
  <a href="#">Home</a>
  <a href="#">About</a>
  <a href="#">Blog</a>
  <a href="#">Protfolio</a>
  <a href="#">Contact</a>
  <div class="animation start-home"></div>
</nav>