{"id":2095,"date":"2024-05-13T13:56:44","date_gmt":"2024-05-13T19:56:44","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=2095"},"modified":"2024-05-13T13:56:45","modified_gmt":"2024-05-13T19:56:45","slug":"the-classic-border-radius-advice-plus-an-unusual-trick","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/the-classic-border-radius-advice-plus-an-unusual-trick\/","title":{"rendered":"The Classic Border Radius Advice, Plus an Unusual Trick"},"content":{"rendered":"\n<p>One million years ago (approximately) <a href=\"https:\/\/css-tricks.com\/public-service-announcement-careful-with-your-nested-border-radii\/\">I posted about the awkward look<\/a> when you nest elements that both have the same <code>border-radius<\/code>. I wrote:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>There probably is some fancy math you could do to figure out the perfect values, but I find eyeballing it works pretty well.<\/p>\n<\/blockquote>\n\n\n\n<p>I didn&#8217;t credit anyone, but I was so young in my career then I have to imagine I heard this advice elsewhere and turned it into a blog post of my own, so sorry if there is an actual first source. But maybe it&#8217;s just the kind of general advice that people to on their own after noticing it and share. It very much <em>goes around<\/em> once in a while, and I&#8217;m glad it does because once you see it, it&#8217;ll bug you forever \u2014\u00a0so let&#8217;s fight it with knowledge.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\"><p lang=\"en\" dir=\"ltr\">Tiny design detail: nested border radii look really funky if they&#39;re the same. To maintain the same curvature, the outer radius = inner radius + padding. <a href=\"https:\/\/t.co\/Oe8ZqFyr4J\">pic.twitter.com\/Oe8ZqFyr4J<\/a><\/p>&mdash; Lily Konings (@lilykonings) <a href=\"https:\/\/twitter.com\/lilykonings\/status\/1567317037126680576?ref_src=twsrc%5Etfw\">September 7, 2022<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\"><p lang=\"en\" dir=\"ltr\">CSS Tip! \ud83e\udd19<br><br>Use custom properties to work out the nested radius of elements for you \ud83d\ude0e<br><br>.parent {<br>  &#8211;nested-radius: calc(var(&#8211;radius) &#8211; var(&#8211;padding));<br>}<br>.nested {<br>  border-radius: var(&#8211;nested-radius);<br>}<br><br>Couldn&#39;t resist making an interactive visual!<a href=\"https:\/\/twitter.com\/CodePen?ref_src=twsrc%5Etfw\">@CodePen<\/a> link below \ud83d\udc47 <a href=\"https:\/\/t.co\/GfMRYvkcda\">https:\/\/t.co\/GfMRYvkcda<\/a> <a href=\"https:\/\/t.co\/vlRbHBSa21\">pic.twitter.com\/vlRbHBSa21<\/a><\/p>&mdash; jhey \u25b2\ud83d\udc3b\ud83c\udf88 (@jh3yy) <a href=\"https:\/\/twitter.com\/jh3yy\/status\/1688542283602231296?ref_src=twsrc%5Etfw\">August 7, 2023<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\"><p lang=\"en\" dir=\"ltr\">If you\u2019ve got a rounded corner on both the outside, and the inside of an element that both have the same value, it looks pretty weird.<br><br>In this Little Design Tip, we dig into a formula to get relative rounded corners, along with a nice CSS utility. <a href=\"https:\/\/t.co\/OrfjY1xTey\">https:\/\/t.co\/OrfjY1xTey<\/a><\/p>&mdash; Andy Bell (@belldotbz) <a href=\"https:\/\/twitter.com\/belldotbz\/status\/1630889802059874310?ref_src=twsrc%5Etfw\">March 1, 2023<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\"><p lang=\"en\" dir=\"ltr\">quick tip for nested radii \u2192 your corners will look a lot better if you set the outer radius to the sum of the inner radius + padding <a href=\"https:\/\/t.co\/oh9ABFSuQ1\">pic.twitter.com\/oh9ABFSuQ1<\/a><\/p>&mdash; Aleks (@aleksliving) <a href=\"https:\/\/twitter.com\/aleksliving\/status\/1687889580555407361?ref_src=twsrc%5Etfw\">August 5, 2023<\/a><\/blockquote><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<\/div><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p>I stand by my advice:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Notice it<\/li>\n\n\n\n<li>Tweak the inner until it looks right.<\/li>\n<\/ul>\n\n\n\n<p>I get that the real math is <code>outer - padding = inner<\/code> but I find that&#8217;s a little too simplistic in practice. If your outer is <code>10px<\/code> and the padding is any more than <code>10px<\/code> (highly common), that means the inner is <code>0<\/code> and zero just doesn&#8217;t feel right either. <\/p>\n\n\n\n<p>I love it when the Web Platform Powers That Be talk about things like this though. This is a small issue that comes up a billion times across a ton of websites, so it should be up for consideration that there becomes a better way. <\/p>\n\n\n\n<p>Adam Argyle <a href=\"https:\/\/github.com\/w3c\/csswg-drafts\/issues\/7707\">kicked off the conversation a few years ago<\/a> and it&#8217;s trickling along it seems. <a href=\"https:\/\/nerdy.dev\/perfect-nested-radius-with-overflow-clip-margin\">His blog post<\/a> explains more, an offers the latest solution:<\/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\">.parent<\/span> {\n  <span class=\"hljs-attribute\">overflow<\/span>: clip;\n  <span class=\"hljs-attribute\">overflow-clip-margin<\/span>: content-box;\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>With this solution, the child elements don&#8217;t need their own <code>border-radius<\/code> at all. They just get clipped (basically like <code>overflow: hidden<\/code>) but the clipping now happens <em>inside<\/em> the padding (that&#8217;s what <code>content-box<\/code> means). Clever stuff, but <a href=\"https:\/\/caniuse.com\/mdn-css_properties_overflow-clip-margin\">not really cross-browser ready<\/a>. <\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_mdGMqOJ\" src=\"\/\/codepen.io\/anon\/embed\/mdGMqOJ?height=450&amp;theme-id=47434&amp;slug-hash=mdGMqOJ&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed mdGMqOJ\" title=\"CodePen Embed mdGMqOJ\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>I like the trick, but I don&#8217;t love that clipping overflow is absolutely required to do it. If standards gets more involved, I would think they could find a better way. <\/p>\n\n\n\n<p>I was just thinking about all this again because I happened to notice that the problem can show itself <a href=\"https:\/\/codepen.io\/chriscoyier\/pen\/dyEPxEv\">when using multiple shadows<\/a>. So I suppose I wouldn&#8217;t hate it if a solution made that nicer in the future as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you nest elements with border-radius, the inner element needs less radius than the outer element.<\/p>\n<p>This is some classic advice on this, and a future-looking fix. <\/p>\n","protected":false},"author":1,"featured_media":2154,"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":[42,7],"class_list":["post-2095","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","tag-border-radius","tag-css"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/05\/image-1.png?fit=1792%2C1024&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2095","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=2095"}],"version-history":[{"count":6,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2095\/revisions"}],"predecessor-version":[{"id":2155,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2095\/revisions\/2155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/2154"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=2095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=2095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=2095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}