CSS space before selector

前端 未结 2 1530
Happy的楠姐
Happy的楠姐 2020-12-07 04:30

I was struggling to understand why this simple CSS class selector was not being picked by my HTML element.

.label-hi :before {
    color:green;
    content:          


        
2条回答
  •  醉酒成梦
    2020-12-07 04:49

    The space between simple selectors is a descendant combinator in CSS. If it were two ordinary selectors separated with space, it would mean 'element matching the second selector, placed anywhere inside the element matching the first selector'. Since the second selector is a pseudo element, the whole selector is equivalent to .label-hi *:before, potentially inserting something into any element inside the element with class label-hi.

提交回复
热议问题