웹표준,웹접근성(html, html5, css, css3, javascript, jQuery, jQueryMobile, snecha, senchaTouch, php, mobileWebApp)

29. nth-child(n) - 자식 선택자 본문

css3/selector

29. nth-child(n) - 자식 선택자

jokack01 2013. 10. 1. 11:16

nth-child(n) - 자식 선택자

: 부모로 부터 지정된 값만큼의 자식 요소를 찾는다.

 

ex) 부모로 부터 3번째 자식인 p 요소를 선택 ( 예 : p:nth-child(3) )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>:nth-child(n)</title>
<style>
p:nth-child(3)
{
background:#ffff00;
}
</style>
</head>
<body>
     
    <h1>:nth-child(n)</h1>
     
    <h3>부모로 부터 지정된 값만큼의 자식 요소를 찾는다.</h3>
    <p>body로 세번째 자식인 p </p>
     
    <div>
        <p>div로 부터 첫번째 자식인 p </p>
        <p>div로 부터 두번째 자식인 p </p>
        <p>div로 부터 세번째 자식인 p </p>   
    </div>
    <div>
        <p>div로 부터 하나인 p </p>
    </div>
  
</body>
</html>