CSS: Style applied to a combination of classes?

前端 未结 4 2027
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 15:43

I\'m not sure this is possible, but is there a syntax to be used in CSS when you want to style an element based on the combination of classes applied to it?

I understand

相关标签:
4条回答
  • 2021-01-31 16:11

    In visual studio 2013 the CSS setting is applied to multiple classes by a "Comma" as follows:

    .bold_green, .bold_blue { color:pink; font-style:italic; }

    0 讨论(0)
  • 2021-01-31 16:12

    Paul and Voyager are correct for the multiple classes case.

    For the "HAS CHILD" case you would use:

    .bold_green .bold_blue { ... } /* note the ' ' (called the descendant selector) */
    

    Which will style any bold_blue elements inside a bold_green element.

    Or if you wanted a DIRECT child:

    .bold_green > .bold_blue { ... } /* this child selector does not work in IE6 */
    

    Which will style only bold_blue elements which have an immediate parent bold_green.

    0 讨论(0)
  • 2021-01-31 16:21
    $('.bold_green.bold_blue').addClass('something-else');
    

    Or in CSS:

    .bold_green.bold_blue { color: pink; }
    

    Notice there's no space between the selectors.

    0 讨论(0)
  • 2021-01-31 16:24

    You don't need anything special, just

    .bold_green.bold_blue { color:pink; font-style:italic; }
    
    0 讨论(0)
提交回复
热议问题