简体   繁体   中英

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). 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, .noblock * {
    display: inline;
}

Notice it would be better to replace * by something else ( input for example if every child is this kind of element)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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