{"id":205,"date":"2008-08-06T19:34:59","date_gmt":"2008-08-07T00:34:59","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=205"},"modified":"2008-08-06T19:34:59","modified_gmt":"2008-08-07T00:34:59","slug":"easy-rounded-corners-with-border-radius","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/easy-rounded-corners-with-border-radius\/","title":{"rendered":"Easy Rounded Corners with Border-Radius"},"content":{"rendered":"<p><a href='http:\/\/cssnewbie.com\/example\/rounded-corners\/'><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/08\/rounded-beauty.gif\" alt=\"\" title=\"rounded corners\" width=\"400\" height=\"187\" class=\"alignnone size-full wp-image-206\" \/><\/a><\/p>\n<p>The realm of CSS is a realm of boxes. <a href=\"http:\/\/cssnewbie.com\/understanding-the-css-box-model\/\" title=\"Understanding the CSS Box Model\">Everything on the page is a box,<\/a> within a box, within a box. No wonder it&#8217;s so common for beginning CSS developers (or, in my case, poor graphic designers with too much CSS experience) to create boxy layouts!<\/p>\n<p>However, the forthcoming CSS3 specification offers us a glimmer of hope in the form of <strong>rounded corners<\/strong>. That&#8217;s right &mdash; once CSS3 is commonly supported, we&#8217;ll be able to childproof all those pointy edges and beautify the web in the process.<\/p>\n<p>And better yet, a few browsers already support rounded corners! As I&#8217;m writing this, you&#8217;re pretty much limited to Mozilla\/Firefox and Safari 3. However, this list is bound to grow as time goes on, so it couldn&#8217;t hurt to start playing around with this feature. Especially considering that, in the browsers that don&#8217;t support rounded corners, nothing bad happens &mdash; the user just sees regular, square corners.<\/p>\n<p>For now, to get the code to work, you&#8217;re stuck using proprietary CSS tags: they won&#8217;t validate, but they&#8217;ll just be ignored by browsers that don&#8217;t support them. The code itself is pretty simple; for example, to create a div with nice rounded corners with a radius of 5 pixels, you&#8217;d just write something like this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">div.rounded {\n\tbackground-color: #666;\n\tcolor: #fff;\n\tfont-weight: bold;\n\tpadding: 10px;\n\t-moz-border-radius: 5px;\n\t-webkit-border-radius: 5px; }<\/pre>\n<p>And this rule will create a div that looks like this:<\/p>\n<p><a href='http:\/\/cssnewbie.com\/example\/rounded-corners\/'><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/08\/rounded-div.gif\" alt=\"\" title=\"rounded-div\" width=\"400\" height=\"86\" class=\"alignnone size-full wp-image-207\" \/><\/a><\/p>\n<p>The two properties of note here are &ldquo;-moz-border-radius&rdquo; and &ldquo;-webkit-border-radius.&rdquo; The former is how to specify the radius &mdash; number of pixels from a hypothetical center point to the edge of the circle created by the rounded corner (see the image below) &mdash; in Mozilla-based browsers. The latter is doing the same thing, but for Safari.<\/p>\n<p><a href='http:\/\/cssnewbie.com\/example\/rounded-corners\/'><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/08\/rounded-detail.gif\" alt=\"\" title=\"rounded-detail\" width=\"400\" height=\"199\" class=\"alignnone size-full wp-image-208\" \/><\/a><\/p>\n<p>The rule isn&#8217;t just limited to curving background colors, either. If you were to add a border to the element, the border would become rounded, as well. For example, <a href=\"http:\/\/cssnewbie.com\/six-ways-style-blockquotes\/\" title=\"Six Ways to Style Blockquotes\">a block quote could be styled<\/a> like so:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">blockquote {\n\tmargin: 1em 20px;\n\tpadding: 10px;\n\tborder: 2px solid #555;\n\tbackground-color: #f2f2f2;\n\tcolor: #555;\n\tfont-size: 140%;\n\ttext-align: justify;\n\t-moz-border-radius: 10px;\n\t-webkit-border-radius: 10px; }<\/pre>\n<p>Resulting in a block quote that has a lot of style, without relying on images to accomplish the task:<\/p>\n<p><a href='http:\/\/cssnewbie.com\/example\/rounded-corners\/'><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/08\/rounded-blockquote.gif\" alt=\"\" title=\"rounded-blockquote\" width=\"400\" height=\"119\" class=\"alignnone size-full wp-image-209\" \/><\/a><\/p>\n<p>And finally, you&#8217;re also not limited to either all rounded corners or none. Using this property, you can specify which corners you want rounded in your CSS. However, it&#8217;s important to note that the Firefox-based version of this rule has deviated a bit from the W3C standard, meaning it&#8217;s written slightly differently than the Safari-based rule. For example, consider these two rules used to round out the top-left corner of a box:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">-moz-border-radius-topleft: 5px;\n-webkit-border-top-left-radius: 5px;<\/pre>\n<p>It&#8217;s a minor difference, in the grand scheme of things, but pretty critical if you want your rounded corners to show up where and how they should! Using the ability to round individual corners, you could generate fancy alert messages:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.alert {\n\tborder: 2px solid #fc0;\n\tpadding: 8px 10px;\n\tfont-size: 120%;\n\tcolor: #c90;\n\tfont-weight: bold;\n\tbackground-color: #ff9;\n\t-moz-border-radius-topleft: 8px;\n\t-webkit-border-top-left-radius: 8px;\t\n\t-moz-border-radius-bottomright: 8px;\n\t-webkit-border-bottom-right-radius: 8px; }<\/pre>\n<p><a href='http:\/\/cssnewbie.com\/example\/rounded-corners\/'><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/08\/rounded-alert.gif\" alt=\"\" title=\"rounded-alert\" width=\"400\" height=\"82\" class=\"alignnone size-full wp-image-210\" \/><\/a><\/p>\n<p>Or, you could apply rounded corners to three of the four edges of a user&#8217;s comment, resulting in a pseudo-voice bubble, all without a single image in sight:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.comment {\n\tborder: 1px solid #999;\n\tbackground-color: #d8d8f4;\n\tmargin: 1em 40px;\n\tpadding: 15px;\n\t-moz-border-radius-topleft: 15px;\n\t-webkit-border-top-left-radius: 15px;\t\n\t-moz-border-radius-topright: 15px;\n\t-webkit-border-top-right-radius: 8px; \t\n\t-moz-border-radius-bottomleft: 15px;\n\t-webkit-border-bottom-left-radius: 15px; }<\/pre>\n<p><a href='http:\/\/cssnewbie.com\/example\/rounded-corners\/'><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/08\/rounded-comment.gif\" alt=\"\" title=\"rounded-comment\" width=\"400\" height=\"86\" class=\"alignnone size-full wp-image-211\" \/><\/a><\/p>\n<p><a href=\"http:\/\/cssnewbie.com\/example\/rounded-corners\/\">You can see all of my examples in action here.<\/a> And these are just a few ways of the hundreds of ways you can harness the power of rounded corners with just a few lines of code. With techniques like this at our disposal, it&#8217;s easy to see why we&#8217;re all so eagerly awaiting CSS3!<\/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>The realm of CSS is a realm of boxes. However, the forthcoming CSS3 specification offers us a glimmer of hope in the form of <strong>rounded corners<\/strong>. And better yet, a few browsers already support rounded corners!  [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/easy-rounded-corners-with-border-radius\/\" title=\"Click to read 'Easy Rounded Corners with Border-Radius'\">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":[165],"tags":[208,151,47,225,49],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/205"}],"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=205"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/205\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}