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

nth-child 몇 번째 자식요소 본문

css

nth-child 몇 번째 자식요소

jokack01 2011. 11. 11. 10:57

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>몇 번째 자식요소</title>
<style type="text/css">
/*
 1st, 2nd, 3rd, 4th
 1, 2, 3, 4, 5, 6, 7, 8, 9, ..... , n
 
 formular 를 사용할 수 있습니다.
 +, - 만 사용이 가능.
 *. / 은 사용할 수 없다.
 키워드 제공.
 2n+1  홀수(odd)
 2n   짝수(even)
*/
/*
body>*:last-child>li:nth-child(2) { }
ul+ol>li:first-child+li { }
ol.selected>:nth-child(2) { }
*/

ul li:nth-child(even) {
 color: #6029df;
}

tr:nth-child(even) {
 /* background: yellow; */
}

col.first {
 background: yellow;
}

</style>
</head>
<body>
 
 <table border="1">
  <caption>test table</caption>
  <col class="first">
  <col class="second">
  <col class="last">
  <tr>
   <th>table cell header</th>
   <th>table cell header</th>
   <th>table cell header</th>
  </tr>
  <tr>
   <td>table cell data</td>
   <td>table cell data</td>
   <td>table cell data</td>
  </tr>
  <tr>
   <td>table cell data</td>
   <td>table cell data</td>
   <td>table cell data</td>
  </tr>
  <tr>
   <td>table cell data</td>
   <td>table cell data</td>
   <td>table cell data</td>
  </tr>
 </table>
 
 <ul>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
 </ul>
 <ol class="selected">
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
  <li>list</li>
 </ol>
 <ul>
  <li>list</li>
  <li>list</li>
  <li>list</li>
 </ul>
 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>

'css' 카테고리의 다른 글

ul, li 의 가운데 정렬  (0) 2012.05.04
float 제어  (0) 2011.11.11
플로팅 디자인의 특징  (0) 2011.11.11
플로팅된 자식요소를 감싸 안으려면?</  (0) 2011.11.11
화면 표시 모듈 - display  (0) 2011.11.11