WEB/HTML_CSS

[CSS] 특정한 요소를 제외시키는 :not 선택자

_yoonie 2023. 6. 21. 13:36

:not 선택자

이미 지정된 css스타일에서 특정한 요소를 제외시킬 경우 사용한다.

선택할 요소:not(제외시킬 요소){...}

예제

<!DOCTYPE html>
<html>
<head>
  <style>
    #test p:not(.highlight) {
      color: blue;
    }
  </style>
</head>
<body>
 <div id="test">
  <p>This is a normal paragraph.</p>
  <p class="highlight">This paragraph has a "highlight" class and will not be affected.</p>
  <p>This is another normal paragraph.</p>
  <p>This is a third normal paragraph.</p>
 </div>
</body>
</html>

결과

This is a normal paragraph.

This paragraph has a "highlight" class and will not be affected.

This is another normal paragraph.

This is a third normal paragraph.

728x90