All tags that start with

Is there any way to to specify styling for all tags that start with some prefix?

For example:

tst-* {
  display: block;
  background: yellow;
}

<tst-some-tag>Some content</tst-some-tag>


The reason why I want such selector is because I'm using Angular and have lots of custom components. All of them should be displayed as block . It could be very comfortable to specify display property for all custom elements ones, instead of adding class every time, when I use them.


If you want to select elements by class-name you could do this: [class^='class']

If you want to select elements by id simply do this: [id^='id']

In both cases you select all elements witch start with the text you put between the single quotation marks, either by class-name or by id.

Variations are also possible: div[class^='class'] or div[id^='id']


You can add another class to those elements in Angular which would have the same css

<tst-some-tag class="tst-class">Some content</tst-some-tag>

You can simply add class to Angular just like jQuery way

var myEl = angular.element( document.querySelector( 'tst-some-tag' ) );
myEl.addClass('tst-class');

根据所有答案,最好的解决方案是编写特定的类并将其添加到每个自定义元素上。

.tst {
  display: block;
  background: yellow;
}

<tst-some-tag class="tst">Some content</tst-some-tag>

链接地址: http://www.djcxy.com/p/37222.html

上一篇: 为什么Java8和Scala2.12 lambda缓存有区别?

下一篇: 所有以此开头的标签