강의

멘토링

로드맵

Inflearn Community Q&A

cyj14983823's profile image
cyj14983823

asked

A real introductory all-in-one development boot camp for non-majors

Learning CSS - 2

다음과 같이 복합 선택자를 줄 경우

Written on

·

156

1

<html>
  <head>
    <title>CSS 기본 사용법</title>
    <style>
      #test p {
        color: blue;
      }

      #test > p {
        color: red;
      }

      #test > div {
        color: orange;
      }
    </style>
  </head>
  <body>
    <div id="test">
      <p>첫 번째 자식</p>
      <p>첫 번째 자식</p>
      <div>
        <p>두 번째 자식</p>
        <p>두 번째 자식</p>
      </div>
    </div>
  </body>
</html>

두 번째 자식에 오렌지 컬러가 적용되어야 하는 거 아닌가요? 그런데 꼭 #test > div >  p {color: orange} 이렇게 자식클래스를 한번 더 써줘야 컬러가 적용되더라고요.ㅠㅠ 

expressreact-nativejavascript머신러닝 배워볼래요? tensorflownodejsreactHTML/CSS

Answer 1

0

grab님의 프로필 이미지
grab
Instructor

#test > div에 color를 적용하더라도 div의 자식인 p 태그의 color에는 직접적으로 영향을 주지 않습니다.

div 자체의 color, 예를 들어 <div>텍스트</div> 이런 경우에 적용이 된다고 보시면 됩니다 :)

cyj14983823's profile image
cyj14983823

asked

Ask a question