How to reference nested classes with css?

前端 未结 5 1630
故里飘歌
故里飘歌 2021-02-20 02:04

When using css, how can I specify a nested class.

Here is my html code:

5条回答
  •  忘了有多久
    2021-02-20 02:18

    In CSS, classes need to be prefixed by a ., ids need to be prefixed by #, and elements don't need to be prefixed at all.

    This is how you need to declare your CSS:

    .box1 .box-body i {
       width: 30px;
    }
    

    Note that box1 and box-body are both classes, while i is an element.


    Example:

    I have listed three different

    elements. This is how they would be accessed in CSS:

    // first div
    .class {
    [some styling]
    }
    
    // second div
    #id {
    [some styling]
    }
    
    // third div
    div {
    [some styling]
    }
    

提交回复
热议问题