02-04-nth-child-table.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Explaining nth-expression</title>
  6. <style id="nth-child" contenteditable>
  7. /**
  8. * the code that's used for stripes in the table. Try changing values!
  9. * (hint: it’s interactive when viewing the demo, using some
  10. * HTML5 + CSS trickery!)
  11. */
  12. tbody tr:nth-child(3n+4) {
  13. background-color: #ddd;
  14. }
  15. </style>
  16. <style>
  17. /**
  18. * Styling for the editable code itself.
  19. * The "monospace, monospace" is a hack to get around a peculiar
  20. * browser default, that makes preformatted text like code
  21. * smaller than the surrounding text.
  22. */
  23. #nth-child {
  24. font-family: monospace, monospace;
  25. display: block;
  26. white-space: pre;
  27. }
  28. /* --- the rest here is not part of the example per se, just some table styling --- */
  29. body {
  30. font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  31. }
  32. head {
  33. display: block;
  34. }
  35. table {
  36. width: 600px;
  37. table-layout: fixed;
  38. }
  39. caption {
  40. font-style: italic;
  41. line-height: 1.8;
  42. }
  43. thead th {
  44. font-weight: bold;
  45. border-bottom: 1px solid;
  46. }
  47. tr td:first-child,
  48. tr th:first-child {
  49. width: 7em;
  50. text-align: center;
  51. }
  52. th, td {
  53. text-align: left;
  54. line-height: 1.4;
  55. }
  56. head title {
  57. display: block;
  58. font-size: 2rem;
  59. padding: 8px;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <table>
  65. <caption>Evaluate what happens when n is a number, starting with 0...</caption>
  66. <thead>
  67. <tr>
  68. <th scope="col">Row &#8470;.</th>
  69. <th>Result</th>
  70. </tr>
  71. </thead>
  72. <tbody>
  73. <tr>
  74. <td>1</td>
  75. <td>Not matched</td>
  76. </tr>
  77. <tr>
  78. <td>2</td>
  79. <td>Not matched</td>
  80. </tr>
  81. <tr>
  82. <td>3</td>
  83. <td>Not matched</td>
  84. </tr>
  85. <tr>
  86. <td>4</td>
  87. <td>3 &times; 0 = 0. Add 4 and get a match for row &#8470; 4!</td>
  88. </tr>
  89. <tr>
  90. <td>5</td>
  91. <td>Not matched</td>
  92. </tr>
  93. <tr>
  94. <td>6</td>
  95. <td>Not matched</td>
  96. </tr>
  97. <tr>
  98. <td>7</td>
  99. <td>3 &times; 1 = 3. Add 4 and get a match for row &#8470; 7!</td>
  100. </tr>
  101. <tr>
  102. <td>8</td>
  103. <td>Not matched</td>
  104. </tr>
  105. <tr>
  106. <td>9</td>
  107. <td>Not matched</td>
  108. </tr>
  109. <tr>
  110. <td>10</td>
  111. <td>3 &times; 2 = 6. Add 4 and get a match for row &#8470; 10!</td>
  112. </tr>
  113. </tbody>
  114. </table>
  115. </body>
  116. </html>