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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:36:36  来源:igfitidea点击:

Bootstrap CSS classes wildcard

csscss-selectors

提问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

此外,这里有相同的西班牙语文档

回答by Rich O'Kelly

The CSS attribute contains selector can be used to achieve this:

CSS 属性包含的选择器可用于实现此目的:

.unique [class*=col]{...}

MDN is a useful reference site for CSS selectors. For reference, the attribute selectors are found here.

MDN 是一个有用的 CSS 选择器参考站点。作为参考,可以在此处找到属性选择器。