CSS: Class name selector- name starts with

前端 未结 2 1705
清歌不尽
清歌不尽 2020-12-11 07:19

I have two different type of class names. The first are named color-*. For example:

color-red
color-blue
color-green

I also ha

2条回答
  •  萌比男神i
    2020-12-11 07:43

    The selector you are using *= matches any attribute containing that string.

    Instead, you want ^=, which matches any attribute beginning with that string.

    A combination would work best:

    a[class^='color-'], a[class*=' color-'] { ... }

    See MDN page on CSS attribute selectors and this other SO answer.

提交回复
热议问题