简体   繁体   English

班级及其所有子级的选择器

[英]Selector for class and all children of it

I have the following 我有以下

<label class="noblock">
  <input> ...
  ...
</label>

I want to specify the CSS display: inline for the class noblock as well as all children of it (anything inside it). 我想指定CSS display: inlinenoblock display: inline以及它的所有子代(其中的任何内容)。 Is there a way to do that? 有没有办法做到这一点?

Yes, you can do it like this: 是的,您可以这样做:

.noblock, .noblock * {
    display: inline;
}

Or if you want to target only direct descendants: 或者,如果您只想定位直接后代:

.noblock, .noblock > * {
    display: inline;
}

You can do: 你可以做:

label.noblock, label.noblock * { display: inline }

The * used here to select all descendants inside any label element with class noblock 此处的*用于选择noblock类的任何label元素内的所有后代

.noblock, .noblock * {
    display: inline;
}

Notice it would be better to replace * by something else ( input for example if every child is this kind of element) 请注意,它会更好,以取代*别的东西( input例如,如果每一个孩子都是这样的元素)

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

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