What exactly does this CSS selector with a comma match?

后端 未结 3 1198
名媛妹妹
名媛妹妹 2021-01-26 20:57

I have a question about CSS selectors.

In my CSS file I have the following code:

.table_legenda th, td {
    text-align: left;
    vertical-align: top;
          


        
3条回答
  •  逝去的感伤
    2021-01-26 21:45

    You are misunderstanding the precedence of the comma.

    .table_legenda th, td {}
    

    is equivalent to:

    .table_legenda th {}
    td {}
    

    and not to:

    .table_legenda th {}
    .table_legenda td {}
    

    You need to specify the complete selector each time you have a comma:

    .table_legenda th,
    .table_legenda td {}
    

    A preprocessing tool such as SASS can give you alternative syntax:

    .table_legenda {
        th, td {}
    }
    

提交回复
热议问题