且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除在伪选择器之前添加的元素

更新时间:2023-12-05 18:24:28

只有CSS可以移除伪元素,所以您需要有一个其他类 display:none ; 之前。首先在CSS中声明该类:

Only CSS can remove pseudo element, so you need to have an other class that display:none; the before. First declare that class in the CSS :

.header {
  ...
  &::before {
    ...
    position: absolute;
    height: 0.5rem;
    ...
  }

  &.no-before::before{
    display:none;
  }
}

然后,当你想删除它时:

Then, when you want to remove it :

$('.header').addClass('no-before'); //Remove before
$('.header').removeClass('no-before'); //Re-add before