{"id":815,"date":"2024-02-13T10:32:19","date_gmt":"2024-02-13T16:32:19","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=815"},"modified":"2024-02-13T10:33:08","modified_gmt":"2024-02-13T16:33:08","slug":"do-you-ever-wish-the-table-you-were-looking-at-had-numbered-rows","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/do-you-ever-wish-the-table-you-were-looking-at-had-numbered-rows\/","title":{"rendered":"Do you ever wish the table you were looking at had numbered rows?"},"content":{"rendered":"\n<p>I had the thought <em>gosh I wish this table&#8217;s rows were numbered<\/em> when I was <a href=\"https:\/\/frontendmasters.com\/blog\/the-popular-vote-of-interop-2024\/\">looking at the big table<\/a> of Interop 2024 popular votes. I don&#8217;t know the that the <code>&lt;table><\/code> <em>needed<\/em> numbering, but when I wanted to know the &#8220;rank&#8221; of some of the items, I found myself wishing it did. <\/p>\n\n\n\n<p>Fortunately, CSS has a quick answer:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">table<\/span> {\n  <span class=\"hljs-attribute\">counter-reset<\/span>: tr;\n  tbody tr {\n    <span class=\"hljs-attribute\">counter-increment<\/span>: tr;\n    :where(td, th):<span class=\"hljs-attribute\">first-child<\/span>::before {\n      content: <span class=\"hljs-string\">\"#\"<\/span> <span class=\"hljs-built_in\">counter<\/span>(tr) <span class=\"hljs-string\">\": \"<\/span>;\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<!--more-->\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_LYaBvVE\" src=\"\/\/codepen.io\/anon\/embed\/LYaBvVE?height=450&amp;theme-id=47434&amp;slug-hash=LYaBvVE&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed LYaBvVE\" title=\"CodePen Embed LYaBvVE\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>The idea there is that you can count things in CSS with <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_counter_styles\/Using_CSS_counters\">CSS counters<\/a>, then display that value as a pseudo element slapped in there wherever you want it. The nesting is nice there as you can just plop it into any ol&#8217; applied CSS and adjust the selector to the table you need it to. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had the thought gosh I wish this table&#8217;s rows were numbered when I was looking at the big table of Interop 2024 popular votes. I don&#8217;t know the that the &lt;table> needed numbering, but when I wanted to know the &#8220;rank&#8221; of some of the items, I found myself wishing it did. Fortunately, CSS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":821,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[106,7,31,105],"class_list":["post-815","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-counters","tag-css","tag-html","tag-tables"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/02\/counted-rows.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=815"}],"version-history":[{"count":3,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions"}],"predecessor-version":[{"id":822,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/815\/revisions\/822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/821"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}