{"id":2496,"date":"2017-06-07T20:45:57","date_gmt":"2017-06-07T20:45:57","guid":{"rendered":"http:\/\/cssreset.com\/?p=2496"},"modified":"2017-06-07T20:45:57","modified_gmt":"2017-06-07T20:45:57","slug":"customize-table-captions-with-the-caption-side-property","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/customize-table-captions-with-the-caption-side-property\/","title":{"rendered":"Customize Table Captions with the Caption Side Property"},"content":{"rendered":"<p>Here&#8217;s a fun front-end fact: did you know that tables can have captions? Tables aren&#8217;t super common anymore unless they&#8217;re being used to display data in a clean an organized fashion (when it comes to this, tables truly can&#8217;t be beat, even though they&#8217;re not terribly mobile friendly), so you might not know about this fun feature of theirs.<\/p>\n<p>First, you&#8217;ll have to implement a table caption in your HTML. \u00a0A good place for the caption to go is within the table, maybe under the main &lt;table&gt; tag or &lt;thead&gt; tags. Here&#8217;s how it might look:<\/p>\n<pre>&lt;table&gt;\r\n&lt;caption&gt;This is my table's caption!&lt;\/caption&gt;\r\n&lt;tr&gt;&lt;td&gt;I'm a cell&lt;\/td&gt;&lt;td&gt;I'm a cell too!&lt;\/td&gt;&lt;\/tr&gt;\r\n&lt;tr&gt;&lt;td&gt;I'm a cell three&lt;\/td&gt;&lt;td&gt;I'm a cell four!&lt;\/td&gt;&lt;\/tr&gt;\r\n&lt;\/table&gt;<\/pre>\n<p>The captions location in relation to the rest of the table doesn&#8217;t necessarily have an effect on where the caption appears, however. With CSS, we can actually manipulate the position of any table caption so that it appears above or below its designated table.<\/p>\n<p>We can do this using the caption-side CSS property. The property takes four values. Top (this positions the caption on top of the table), bottom (as you can probably guess, this positions the caption below the table), and initial and inherit (naturally). Use of the CSS property is pretty straightforward, but we&#8217;re still going to show you what it looks like in context anyway.<\/p>\n<p>If you want to position your table caption above your table, this is what your CSS would need to look like:<\/p>\n<pre>caption{\r\n\u00a0 \u00a0 caption-side: top;\r\n}<\/pre>\n<p>Easy enough, right?<\/p>\n<p>To position your table caption below your table, you&#8217;d just need the following snippet.<\/p>\n<pre>caption{\r\n\u00a0 \u00a0 caption-side: bottom;\r\n}<\/pre>\n<p>Remember, tables aren&#8217;t exactly the most mobile-friendly HTML element, so use them sparingly, and never use them to create a page structure or grid situation &#8212; that&#8217;s what divs are for. Happy coding!<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a fun front-end fact: did you know that tables can have captions? Tables aren&#8217;t super common anymore unless they&#8217;re being used to display data in a clean an organized fashion (when it comes to this, tables truly can&#8217;t be [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/customize-table-captions-with-the-caption-side-property\/\" title=\"Click to read 'Customize Table Captions with the Caption Side Property'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,36],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2496"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=2496"}],"version-history":[{"count":1,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2496\/revisions"}],"predecessor-version":[{"id":2497,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2496\/revisions\/2497"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=2496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=2496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=2496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}