神奇的 ~ 选择符

对于当前 hover 的 li ,其对应伪元素的下划线的定位是 left: 100%,而对于 li:hover ~ li::before,它们的定位是 left: 0。

ul li {
    float: left;
    width: 20%;
    height: 60px;
    line-height: 60px;
    text-align: center;
    border-bottom: 0px solid #000;
    margin-right: 5%;
    cursor: pointer;
    position: relative;
}
li.active {
    height: 50px;
    line-height: 50px;
    border-bottom: 2px solid #000;
}
li::before {
    content: "";
    position: absolute;
    top: 0;
    left: 100%;
    width: 0;
    height: 50px;
    border-bottom: 2px solid #000;
    transition: 0.2s all linear;
}
li:hover::before {
    width: 100%;
    left: 0;
}
li:hover~li::before {
    left: 0;
}

 

 CSSTab栏下划线跟随效果

 

 

 

相关文章:

  • 2021-11-16
  • 2021-11-01
  • 2021-09-11
  • 2021-11-13
  • 2021-11-14
  • 2021-11-27
  • 2018-07-31
  • 2021-12-03
猜你喜欢
  • 2021-09-25
  • 2021-09-19
  • 2021-09-29
  • 2021-09-19
  • 2021-09-19
  • 2021-09-19
  • 2018-02-11
相关资源
相似解决方案