{"id":2349,"date":"2021-05-14T08:22:02","date_gmt":"2021-05-14T07:22:02","guid":{"rendered":"https:\/\/www.sachaheck.net\/blog\/?p=2349"},"modified":"2021-05-14T08:30:53","modified_gmt":"2021-05-14T07:30:53","slug":"html-css-tip-creating-tables-with-indent-to-right","status":"publish","type":"post","link":"https:\/\/www.sachaheck.net\/blog\/digital-media\/html-css-tip-creating-tables-with-indent-to-right","title":{"rendered":"HTML \/ CSS tip: Creating tables with indent to right"},"content":{"rendered":"\n\n\n<p>This week I was looking to find an answer to pimp up tables I have been creating on a website for a restaurant. The tables show the menu, here is a simple example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/code-before.jpg\"><img loading=\"lazy\" width=\"516\" height=\"436\" src=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/code-before.jpg\" alt=\"\" class=\"wp-image-2350\" srcset=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/code-before.jpg 516w, https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/code-before-300x253.jpg 300w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><\/a><\/figure>\n\n\n\n<p>In the browser this table code looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/browser-before.jpg\"><img loading=\"lazy\" width=\"358\" height=\"126\" src=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/browser-before.jpg\" alt=\"\" class=\"wp-image-2351\" srcset=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/browser-before.jpg 358w, https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/browser-before-300x106.jpg 300w\" sizes=\"(max-width: 358px) 100vw, 358px\" \/><\/a><\/figure>\n\n\n\n<p>Now, what I wanted to achieve was, that the price shall always align to the right. Like in InDesign you just put in an indent to right. However with just the HTML code the position of the price is always different depending on the largest row of the whole table.<\/p>\n\n\n\n<p>The solution is to format the table with a little CSS. I contacted a webdeveloper I know, <a href=\"https:\/\/twitter.com\/mitch0z\" target=\"_blank\" rel=\"noreferrer noopener\">Misch Strotz<\/a> from <a href=\"https:\/\/www.goneon.lu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Neon Marketing Technology<\/a> and he quickly told me his way of solving this issue and it worked perfectly, Thank you very much :-) To not forget the little trick, I just share it here for everybody and also for me to find it in the future ;-)<\/p>\n\n\n\n<p>So first we define CSS classes for the first column and the second column, like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/define-classes.jpg\"><img loading=\"lazy\" width=\"421\" height=\"67\" src=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/define-classes.jpg\" alt=\"\" class=\"wp-image-2352\" srcset=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/define-classes.jpg 421w, https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/define-classes-300x48.jpg 300w\" sizes=\"(max-width: 421px) 100vw, 421px\" \/><\/a><\/figure>\n\n\n\n<p>You can choose any name for the class you like. I took &#8222;meal&#8220; for the first column and &#8222;price&#8220; for the second column. You do that for every data in your column. Afterwards we can use these classes to tell the browser what it should do with these 2 columns. Here is the CSS:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/CSS-code.jpg\"><img loading=\"lazy\" width=\"343\" height=\"70\" src=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/CSS-code.jpg\" alt=\"\" class=\"wp-image-2353\" srcset=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/CSS-code.jpg 343w, https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/CSS-code-300x61.jpg 300w\" sizes=\"(max-width: 343px) 100vw, 343px\" \/><\/a><\/figure>\n\n\n\n<p>So for the meal column we defined a width of 100% minus the second column, here we defined 130 px. Then for the price column we defined those 130px and told it to align to the right with the command <code>text-align<\/code>.<\/p>\n\n\n\n<p>That&#8217;s it. With this little code, the table now displays beautifully. Here is the actual styled example from the website:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/styled-end-result.jpg\"><img loading=\"lazy\" width=\"800\" height=\"459\" src=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/styled-end-result.jpg\" alt=\"\" class=\"wp-image-2359\" srcset=\"https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/styled-end-result.jpg 800w, https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/styled-end-result-300x172.jpg 300w, https:\/\/www.sachaheck.net\/blog\/wp-content\/uploads\/2021\/05\/styled-end-result-768x441.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/figure>\n<div class=\"shariff\"><ul class=\"shariff-buttons theme-default orientation-horizontal buttonsize-medium\"><li class=\"shariff-button twitter shariff-nocustomcolor\" style=\"background-color:#1e3050\"><a href=\"https:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.sachaheck.net%2Fblog%2Fdigital-media%2Fhtml-css-tip-creating-tables-with-indent-to-right&text=HTML%20%2F%20CSS%20tip%3A%20Creating%20tables%20with%20indent%20to%20right\" title=\"Bei X (Twitter) teilen\" aria-label=\"Bei X (Twitter) teilen\" role=\"button\" rel=\"noreferrernoopener nofollow\" class=\"shariff-link\" style=\"; background-color:#000000; color:#fff\" target=\"_blank\"><span class=\"shariff-icon\" style=\"\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" height=\"1em\" viewBox=\"0 0 512 512\"><!--! Font Awesome Free 6.4.2 by @fontawesome - https:\/\/fontawesome.com License - https:\/\/fontawesome.com\/license (Commercial License) Copyright 2023 Fonticons, Inc. --><style>svg{fill:#ffffff}<\/style><path d=\"M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z\"\/><\/svg><\/span><span class=\"shariff-text\">twittern<\/span>&nbsp;<\/a><\/li><li class=\"shariff-button facebook shariff-nocustomcolor\" style=\"background-color:#4273c8\"><a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwww.sachaheck.net%2Fblog%2Fdigital-media%2Fhtml-css-tip-creating-tables-with-indent-to-right\" title=\"Bei Facebook teilen\" aria-label=\"Bei Facebook teilen\" role=\"button\" rel=\"noreferrernoopener nofollow\" class=\"shariff-link\" style=\"; background-color:#3b5998; color:#fff\" target=\"_blank\"><span class=\"shariff-icon\" style=\"\"><svg width=\"32px\" height=\"20px\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 18 32\"><path fill=\"#3b5998\" d=\"M17.1 0.2v4.7h-2.8q-1.5 0-2.1 0.6t-0.5 1.9v3.4h5.2l-0.7 5.3h-4.5v13.6h-5.5v-13.6h-4.5v-5.3h4.5v-3.9q0-3.3 1.9-5.2t5-1.8q2.6 0 4.1 0.2z\"\/><\/svg><\/span><span class=\"shariff-text\">teilen<\/span>&nbsp;<\/a><\/li><li class=\"shariff-button linkedin shariff-nocustomcolor\" style=\"background-color:#1488bf\"><a href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=https%3A%2F%2Fwww.sachaheck.net%2Fblog%2Fdigital-media%2Fhtml-css-tip-creating-tables-with-indent-to-right\" title=\"Bei LinkedIn teilen\" aria-label=\"Bei LinkedIn teilen\" role=\"button\" rel=\"noreferrernoopener nofollow\" class=\"shariff-link\" style=\"; background-color:#0077b5; color:#fff\" target=\"_blank\"><span class=\"shariff-icon\" style=\"\"><svg width=\"32px\" height=\"20px\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 27 32\"><path fill=\"#0077b5\" d=\"M6.2 11.2v17.7h-5.9v-17.7h5.9zM6.6 5.7q0 1.3-0.9 2.2t-2.4 0.9h0q-1.5 0-2.4-0.9t-0.9-2.2 0.9-2.2 2.4-0.9 2.4 0.9 0.9 2.2zM27.4 18.7v10.1h-5.9v-9.5q0-1.9-0.7-2.9t-2.3-1.1q-1.1 0-1.9 0.6t-1.2 1.5q-0.2 0.5-0.2 1.4v9.9h-5.9q0-7.1 0-11.6t0-5.3l0-0.9h5.9v2.6h0q0.4-0.6 0.7-1t1-0.9 1.6-0.8 2-0.3q3 0 4.9 2t1.9 6z\"\/><\/svg><\/span><span class=\"shariff-text\">mitteilen<\/span>&nbsp;<\/a><\/li><\/ul><\/div>","protected":false},"excerpt":{"rendered":"<p>This week I was looking to find an answer to pimp up tables I have been creating on a website for a restaurant. The tables show the menu, here is a simple example: In the browser this table code looks like this: Now, what I wanted to achieve was, that the price shall always align&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[100,583,584],"tags":[191,78,585,586],"_links":{"self":[{"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/posts\/2349"}],"collection":[{"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/comments?post=2349"}],"version-history":[{"count":6,"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/posts\/2349\/revisions"}],"predecessor-version":[{"id":2362,"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/posts\/2349\/revisions\/2362"}],"wp:attachment":[{"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/media?parent=2349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/categories?post=2349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sachaheck.net\/blog\/wp-json\/wp\/v2\/tags?post=2349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}