How to use CSS first-child but excluding text content

后端 未结 4 1779
渐次进展
渐次进展 2021-01-19 01:38

This snippet doesn\'t work the way I expect:

4条回答
  •  粉色の甜心
    2021-01-19 02:00

    As far as I can tell, no, you cannot differentiate between elements with or without a sibling text node using CSS alone:

    div li span:first-child {
      font-style: italic;
    }
    
    div li:first-child span {
      font-weight: bold;
    }
    
    div li:empty span:first-child {
      color:red;
    }
    
    div li span:only-child {
      font-size: 20px;
    }
    • This is a test
    • And this is also a test
    • another test

提交回复
热议问题