ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 선택자정리
    HTML&CSS/CSS 2023. 1. 3. 22:47
    /* 모든 h1태그 */  
    h1{
        color: orange;
    }
    
    /* 'important'라는 클래스를 갖고 있는 모든 태그  */
    .important {
        color: orange;
    }
    
    /* 'favorite'라는 아이디를 갖고 있는 태그 */  
    #favorite {
        color:blue;
    }
    
    
    자식 (children)
    /* 'div1' 클래스를 갖고 있는 요소의 자식 중 모든 <i> 태그 */
    .div i{
        color:orange;
    }
    
    직속 자식 (direct children)
    
    /* 'div1' 클래스를 갖고 있는 요소의 직속 자식 중 모든 <i> 태그 */
    .div1 > i{
        color:orange;
    }
    
    복수 선택
    /* 'two' 클래스를 가지고 있는 태그 모두와 'four' 클래스를 가지고 있는 태그 모두 선택 */
    .two, .four {
        color: orange;
    }
    
    여러 조건  
    /* 'outside' 클래스를 갖고 있으면서 'one' 클래스도 갖고 있는 태그 */
    .outside.one {
        color:blue;
    }   
    /* 'inside' 클래스를 갖고 있으면서 'two' 클래스도 갖고 있는 태그 */
    .inside.two{
        color:orange;
    }
    
    Pseudo-class (가상 클래스)
    콜론(:)을 사용하면 몇 가지 '가상 클래스'를 선택할 수 있습니다.
    
    n번째 자식
    /* .div1의 자식인 <p> 태그 중 3번째 */
    .div1 p:nth-child(3) {
        color:blue;
    }   
    
    /* .div1의 자식인 <p> 태그 중 첫 번째 */  
    .div1 p:first-child {
        color:red;
    }
    
    /* .div1의 자식인 <p> 태그 중 마지막  */
    .div1 p:last-child {
        color: green;
    }
    
    마우스 오버 (hover)
    h1:hover{
        color:green;
    }

    'HTML&CSS > CSS' 카테고리의 다른 글

    포지션(Position)  (0) 2023.01.04
    디스플레이(display)  (0) 2023.01.04
    마진(Margin) vs 패딩(Padding)  (0) 2023.01.03
    둥근모서리/배경색/배경이미지/그림자  (0) 2023.01.02
    OverFlow  (0) 2022.12.20

    댓글

Designed by Tistory.