Removing an element added by ::before pseudo selector

前端 未结 3 802
谎友^
谎友^ 2021-01-13 20:14

I have the following case: (styling is done in SASS and unnecessary stylings are omitted.)

.header {
  ...
  &::before {
    ...
    position: absolute;         


        
3条回答
  •  無奈伤痛
    2021-01-13 20:58

    The usual way is to create a more specific rule that applies to the element(s) in question (or a later rule with the same specificity), and specify display: none to hide the pseudo in that case.

    For example: Here, I want to have an X in front of , but not if they're in .header:

    span.foo::before {
      content: 'X ';
    }
    .header span.foo::before {
      display: none;
    }
    These have the X: span.foo 1 span.foo 2 span.foo 3
    These don't: span.foo 4 span.foo 5 span.foo 6

提交回复
热议问题