CSS selects the method to add styles to all child elements

Time:2020-11-17

method:

Take less as an example


.lk-toolbar {
    .el-input {
        width: 169px;
        margin-right: 10px;
    }
    > * {
        margin-bottom: 20px;
    }
}

The above code successfully implements the margin bottom: 20px of all sub elements under. LK toolbar

In this way, we can avoid listing all kinds of possible sub element types


.lk-toolbar {
    .el-input {
        width: 169px;
        margin-right: 10px;
        margin-bottom: 20px;
    }
    .el-button, .el-date-editor {
        margin-bottom: 20px;
    }
}

Application scenario (effect)

Perception (nonsense)

At first, I wonder if there is such a selector in CSS to select all the child elements. After reading the document, I found that although there is no selector, the most basic method has been told you. The rest depends on your own creativity (see if you can use it flexibly!)

Tutorial OS: “the method is here, whether you can use it depends on yourself.”

This article introduces the method of selecting all sub elements to add styles in CSS. For more relevant CSS sub elements, please search the previous articles of developeppaer or continue to browse the related articles below. I hope you can support developeppaer more in the future!