Bootstrap CSS 类通配符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25954181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap CSS classes wildcard
提问by Devin
I want to target all of the columns inside a Bootstrap container so I can give then a similar style. For example:
我想以 Bootstrap 容器内的所有列为目标,这样我就可以给出类似的样式。例如:
<div class="container unique">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
</div>
</div>
I can target this with CSS:
我可以用 CSS 来定位这个:
.unique .col-md-3{...}
but what I want to do is when I have many different col-*
elements, to target them all together.
但我想要做的是当我有许多不同的col-*
元素时,将它们集中在一起。
I tried this:
我试过这个:
.unique .col-*{...}
but it didn't work. Can I do this with CSS?
但它没有用。我可以用 CSS 做到这一点吗?
回答by Devin
Pedro, what you're looking for is called attribute selector. In your particular case, you can use it like this:
佩德罗,你要找的东西叫做属性选择器。在您的特定情况下,您可以像这样使用它:
.unique [class~=col] {color:red }
but you could also use this with more wide options like
但您也可以将其与更广泛的选项一起使用,例如
[class*='col-']
to cover preceding white spaces.
覆盖前面的空格。
Also, here you have the same documentation in Spanish
此外,这里有相同的西班牙语文档