{"id":4725,"date":"2024-12-11T14:01:17","date_gmt":"2024-12-11T19:01:17","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=4725"},"modified":"2024-12-11T14:01:18","modified_gmt":"2024-12-11T19:01:18","slug":"responsive-tables-readable-paragraphs","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/responsive-tables-readable-paragraphs\/","title":{"rendered":"Responsive Tables &amp; Readable Paragraphs"},"content":{"rendered":"\n<p>I have this habit where when I&#8217;m watching a TV show where I like to read about it on my phone while I&#8217;m watching it. Reviews, summaries, fan theories, whatever. Seems like that would be distracting \u2014 but I think it&#8217;s extra engaging sometimes. I&#8217;d often end up on Wikipedia where they do episode informational summaries in a particular layout where the small screen layout had a horribly obnoxious side effect.<\/p>\n\n\n\n<p>Here (was) the issue:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"573\" height=\"1024\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/CleanShot-2024-12-05-at-11.26.07%402x.png?resize=573%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-4726\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/CleanShot-2024-12-05-at-11.26.07%402x.png?resize=573%2C1024&amp;ssl=1 573w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/CleanShot-2024-12-05-at-11.26.07%402x.png?resize=168%2C300&amp;ssl=1 168w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/CleanShot-2024-12-05-at-11.26.07%402x.png?resize=768%2C1372&amp;ssl=1 768w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/CleanShot-2024-12-05-at-11.26.07%402x.png?resize=860%2C1536&amp;ssl=1 860w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/CleanShot-2024-12-05-at-11.26.07%402x.png?resize=1147%2C2048&amp;ssl=1 1147w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/CleanShot-2024-12-05-at-11.26.07%402x.png?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/figure>\n\n\n\n<p>To their credit, they made the data table responsive in that it&#8217;s not zoomed out or cut off, you can horizontally scroll it. But horizontal scrolling is super terrible when you&#8217;re trying to read a paragraph of text. <\/p>\n\n\n\n<p>Also to their credit, they&#8217;ve also (recently?) made this a bit better. <\/p>\n\n\n\n<p>They put a wrapper element over the show description and added <code>max-width: 90vw;<\/code> to the styles. It was kinda funny though, as I happen to notice that and I was looking at a page where that was <em>still a smidge too wide<\/em> and it was cutting off like 50px of text so there was still a bit of horizontal scrolling needed. <\/p>\n\n\n\n<p>The problem is that <code>90vw<\/code> is a <strong>&#8220;magic number&#8221;<\/strong>. It&#8217;s essentially saying &#8220;pretty close to the width of the screen, but like, not all of it, because there is some padding and stuff the account for.&#8221; It&#8217;s just a guess. I get it, sometimes you gotta just be close and move on, but here I&#8217;ve literally seen it fail, which is the whole downside of magic numbers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"837\" height=\"1024\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-05-at-11.33.40%E2%80%AFAM-1.png?resize=837%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-4729\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-05-at-11.33.40%E2%80%AFAM-1.png?resize=837%2C1024&amp;ssl=1 837w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-05-at-11.33.40%E2%80%AFAM-1.png?resize=245%2C300&amp;ssl=1 245w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-05-at-11.33.40%E2%80%AFAM-1.png?resize=768%2C940&amp;ssl=1 768w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-05-at-11.33.40%E2%80%AFAM-1.png?resize=1256%2C1536&amp;ssl=1 1256w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-05-at-11.33.40%E2%80%AFAM-1.png?resize=1674%2C2048&amp;ssl=1 1674w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-05-at-11.33.40%E2%80%AFAM-1.png?w=2000&amp;ssl=1 2000w\" sizes=\"auto, (max-width: 837px) 100vw, 837px\" \/><\/figure>\n\n\n\n<p>If they were trying to be perfect about it, that <code>max-width<\/code> would be set to account for all the other spacing. Something like:<\/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-class\">.shortSummaryText<\/span> {\n  <span class=\"hljs-comment\">\/* Viewport width minus 1rem of body padding on each side \n     and 0.5rem of padding inside the table cell, \n     minus the borders. *\/<\/span>\n  <span class=\"hljs-attribute\">max-width<\/span>: <span class=\"hljs-built_in\">calc<\/span>(<span class=\"hljs-number\">100<\/span>dvw - <span class=\"hljs-number\">3rem<\/span> - <span class=\"hljs-number\">2px<\/span>); \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<p>Maybe those things are custom properties that could be grabbed, which would be even nicer. This kind of thing can be hard to maintain so I get it.<\/p>\n\n\n\n<p>Notice in the screenshot above they also added <code>position: sticky;<\/code> and stuck it to the <code>left<\/code> side, which is a super classy touch! That way when the table is scrolled to see the other bits of information in a row, the readable paragraphs stay readable, rather than scroll over into just blank white nothingness.<\/p>\n\n\n\n<p>I did a fork of the classic <a href=\"https:\/\/adrianroselli.com\/2020\/11\/under-engineered-responsive-tables.html\">Under-Engineered Responsive Tables<\/a> to include this feature. <\/p>\n\n\n\n<div class=\"wp-block-group ticss-cbff1fc8\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_EaYPbGE\" src=\"\/\/codepen.io\/anon\/embed\/EaYPbGE?height=850&amp;theme-id=47434&amp;slug-hash=EaYPbGE&amp;default-tab=result\" height=\"850\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed EaYPbGE\" title=\"CodePen Embed EaYPbGE\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You can make a table responsive by letting it horizontally scroll. But if you do that, make sure any paragraph style text isn&#8217;t any wider than the screen.<\/p>\n","protected":false},"author":1,"featured_media":4796,"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":[1],"tags":[7,272,271],"class_list":["post-4725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","tag-css","tag-responsive-design","tag-table"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/12\/pexels-photo-9572529.jpeg?fit=1880%2C1253&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/4725","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=4725"}],"version-history":[{"count":7,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/4725\/revisions"}],"predecessor-version":[{"id":4797,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/4725\/revisions\/4797"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/4796"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=4725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=4725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=4725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}