简体   繁体   English

CSS选择器:具有以下任一类的班级子级

[英]CSS Selector: Children of class with one of the following classes

I have a requirement for a CSS selector where all children of a given class which contain one of n classes are affected. 我有一个CSS选择器的要求,其中包含n个类之一的给定类的所有子代都会受到影响。

My container is .k-editor and the children I am looking to affect are all the bootstrap columns col-xs-1, col-xs-2 etc. 我的容器是.k-editor ,我要影响的孩子是所有引导列col-xs-1, col-xs-2等。

So I tried this 所以我尝试了这个

.k-editor 
.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1,
.col-xs-2, .col-sm-2, .col-md-2, .col-lg-2,
.col-xs-3, .col-sm-3, .col-md-3, .col-lg-3,
.col-xs-4, .col-sm-4, .col-md-4, .col-lg-4,
.col-xs-5, .col-sm-5, .col-md-5, .col-lg-5,
.col-xs-6, .col-sm-6, .col-md-6, .col-lg-6,
.col-xs-7, .col-sm-7, .col-md-7, .col-lg-7,
.col-xs-8, .col-sm-8, .col-md-8, .col-lg-8,
.col-xs-9, .col-sm-9, .col-md-9, .col-lg-9,
.col-xs-10, .col-sm-10, .col-md-10, .col-lg-10,
.col-xs-11, .col-sm-11, .col-md-11, .col-lg-11,
.col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
    padding: 0;
}

but this seems to ignore the .k-editor parent and apply itself to all columns. 但这似乎忽略了.k-editor父级,并将其自身应用于所有列。

Anyone able to provide some input on what I might be doing wrong? 任何人都可以就我可能做错的事情提供一些意见吗?

This code can be shortened: 此代码可以缩短:

.keditor [class^="col"] {
     padding: 0;
}

This is the shortest solution: .k-editor [class^="col"] will match all the children of .k-editor whose class starts with col . 这是最短的解决方案: .k-editor [class^="col"]将匹配所有以col开头的.k-editor的子级。

The other way is to prefix .k-editor to each of your comma-separated selectors: 另一种方法是将.k-editor前缀给每个逗号分隔的选择器:

.k-editor .col-xs-1, .k-editor .col-sm-1, .k-editor .col-md-1, .k-editor .col-lg-1 etc .k-editor .col-xs-1, .k-editor .col-sm-1, .k-editor .col-md-1, .k-editor .col-lg-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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