개발햄비

[CSS] Pseudo Selector 정리 본문

개발/CSS

[CSS] Pseudo Selector 정리

개발햄 2019. 9. 12. 22:35
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Selectors and Pseudo Selectors</title>
  <style>
    input[type="submit"]{
      background-color: red;
    }
    input{
      border: 1px solid yellow;
    }
    .box{
      background-color: green;
      display: block;
      height: 100px;
      border: 1px solid black;
    }
     /* 첫번째 자식*/
    .box:first-child{
      background-color: yellow;
    }
     /* n번째 자식*/
    .box:nth-child(2n){
      background-color: gold;
    }
    /* 마지막 자식*/
    .box:last-child{
      background-color: pink;
    }
    /* 형제 */
    input + .box{
      background-color: pink;
    }
    .box > .box{
      /* 직계 */
      background-color: yellowgreen;
      width: 100px;
    }
  </style>
</head>
<body>
<div class="test">
  <div class="box">1
    <div class="box">1-1</div>
  </div>
  <div class="box">2</div>
  <div class="box">3
    <input type="text" >3-1
    <input type="submit">3-2
  </div>
  <div class="box">4</div>
  <div class="box">5</div>
  <div class="box">6</div>
</div>
</div>
</body>
</html>

'개발 > CSS' 카테고리의 다른 글

[CSS] 세로 오픈 메뉴 예제  (0) 2019.09.08
[CSS] display: block 과 inline-block 그리고 inline 차이  (0) 2019.09.07