简体   繁体   中英

Why aren't my attribute selectors working?

I'm trying to use multiple attribute selectors, but my code just doesn't seem to work at least in CodePen...

I googled a lot, but I just can't find a solution.

I've written them in SCSS:

*[class^="inset"] {
  &[class*="-t0"] {
    top: 0;
  }
  &[class*="-r0"] {
    right: 0;
  }
  &[class*="-b0"] {
    bottom: 0;
  }
  &[class*="-l0"] {
    left: 0;
  }
}

here's a runnable demo with compiled CSS:

 *[class^="inset"][class*="-t0"] { top: 0; } *[class^="inset"][class*="-r0"] { right: 0; } *[class^="inset"][class*="-b0"] { bottom: 0; } *[class^="inset"][class*="-l0"] { left: 0; }
 <button class="inset-t0">Button</button>

Selecting like this implies there are two css classes in the element, like

<button class="inset -t0"></button>

You can simply do the following:

.inset {
  &-t0 {
    top: 0;
  }
  &-r0 {
    right: 0;
  }
  &-b0 {
    bottom: 0;
  }
  &-l0 {
    left: 0;
  }
}
.inset {
  &-t0 {
    top: 0;
  }

  &-r0 {
    right: 0;
  }

  &-b0 {
     bottom: 0;
  }

  &-l0 {
    left: 0;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM