{"id":3110,"date":"2022-06-01T14:09:00","date_gmt":"2022-06-01T14:09:00","guid":{"rendered":"https:\/\/rengga.dev\/blog\/?p=3110"},"modified":"2023-06-12T14:30:56","modified_gmt":"2023-06-12T14:30:56","slug":"css-tutorial-no-jank-css-stripes","status":"publish","type":"post","link":"https:\/\/rengga.dev\/blog\/css-tutorial-no-jank-css-stripes\/","title":{"rendered":"CSS Tutorial &#8211; No-Jank CSS Stripes"},"content":{"rendered":"<p><span style=\"color: #ef3207;\"><a style=\"color: #ef3207;\" href=\"https:\/\/rengga.dev\/\" target=\"_blank\" rel=\"noopener\"><strong>Rengga Dev<\/strong><\/a> <\/span>-My mind goes immediately to repeating-linear-gradient\u00a0and\u00a0hard-stop gradients\u00a0when thinking of creating\u00a0stripes in CSS. You make one stripe by using the same color between two color stops, and another stripe (or more) but using a different color between two colors stops (sharing the one in the middle).<\/p>\n<p>So like:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\">background: repeating-linear-gradient(\r\n  45deg,\r\n  black,\r\n  black 10px,\r\n  #444 10px,\r\n  #444 11px\r\n);<\/pre>\n<p>That will make angled dark gray stripes 10px apart on black.<\/p>\n<p>But this is how it renders on my screen:<\/p>\n<figure id=\"attachment_3112\" aria-describedby=\"caption-attachment-3112\" style=\"width: 1000px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3112 size-full\" src=\"https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-11.59.45-AM.webp\" alt=\"CSS Tutorial - No-Jank CSS Stripes\" width=\"1000\" height=\"250\" srcset=\"https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-11.59.45-AM.webp 1000w, https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-11.59.45-AM-300x75.webp 300w, https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-11.59.45-AM-768x192.webp 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption id=\"caption-attachment-3112\" class=\"wp-caption-text\">CSS Tutorial &#8211; No-Jank CSS Stripes<\/figcaption><\/figure>\n<p>Can you see that rendering jankiness where one or two of the stripes seems lighter and thinner than the others? I have no idea why. I assume it\u2019s something to do with sub-pixel rendering or the like. This is not hard to replicate. It\u2019s not just these two colors or this particular angle is just about any stripes created at all with\u00a0<code>repeating-linear-gradient<\/code>. It stops being so noticeable with thicker stripes though (say,\u00a0<code>5px<\/code>\u00a0and thicker).<\/p>\n<h2 id=\"h-so-what-do-you-do\">So, what do you do?<\/h2>\n<p>Use this\u00a0<a href=\"https:\/\/stripesgenerator.com\/\" rel=\"noopener\">nice little generator tool<\/a>\u00a0thing:<\/p>\n<figure id=\"attachment_3113\" aria-describedby=\"caption-attachment-3113\" style=\"width: 1000px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3113 size-full\" src=\"https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-1.45.08-PM.webp\" alt=\"Stripes Generator\" width=\"1000\" height=\"823\" srcset=\"https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-1.45.08-PM.webp 1000w, https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-1.45.08-PM-300x247.webp 300w, https:\/\/rengga.dev\/blog\/wp-content\/uploads\/2022\/08\/Screen-Shot-2021-01-21-at-1.45.08-PM-768x632.webp 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption id=\"caption-attachment-3113\" class=\"wp-caption-text\">Stripes Generator<\/figcaption><\/figure>\n<p>It does whatever fancy math necessary to get it right. You can\u00a0<a href=\"https:\/\/stripesgenerator.com\/js\/functions.js\" rel=\"noopener\">see the unminified JavaScript here<\/a>. Search for\u00a0<code>\/ GET BACKGROUND SIZE \/<\/code>\u00a0to see all the math going on. Whatever it\u2019s doing there, the stripes come out perfectly.<\/p>\n<p>Kind of a shame\u00a0<code>repeating-linear-gradient<\/code>\u00a0doesn\u2019t have better visual output as that\u2019s so much easier to reason about, but hey, you gotta do what you gotta do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rengga Dev -My mind goes immediately to repeating-linear-gradient\u00a0and\u00a0hard-stop gradients\u00a0when thinking of creating\u00a0stripes <a class=\"read-more\" href=\"https:\/\/rengga.dev\/blog\/css-tutorial-no-jank-css-stripes\/\" title=\"CSS Tutorial &#8211; No-Jank CSS Stripes\" itemprop=\"url\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":3742,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,2],"tags":[268,294,197,103,227],"newstopic":[],"class_list":{"0":"post-3110","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-html-css","8":"category-web-design","9":"tag-css-grid","10":"tag-css-stripes","11":"tag-css-tutorial","12":"tag-web-design","13":"tag-web-designer"},"_links":{"self":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/comments?post=3110"}],"version-history":[{"count":1,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3110\/revisions"}],"predecessor-version":[{"id":3114,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3110\/revisions\/3114"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media\/3742"}],"wp:attachment":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media?parent=3110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/categories?post=3110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/tags?post=3110"},{"taxonomy":"newstopic","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/newstopic?post=3110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}