{"id":2242,"date":"2017-02-20T04:08:41","date_gmt":"2017-02-20T04:08:41","guid":{"rendered":"http:\/\/cssreset.com\/?p=2242"},"modified":"2017-02-20T04:08:41","modified_gmt":"2017-02-20T04:08:41","slug":"css-basics-how-to-make-shapes-part-i","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/css-basics-how-to-make-shapes-part-i\/","title":{"rendered":"CSS Basics: How to Make Shapes, Part I"},"content":{"rendered":"<p>In CSS, it&#8217;s relatively easy and fairly common to use div elements to create different recognizable shapes. All it takes is one div element, a little (sometimes a lot, depending on the desired shape) CSS, and usually a basic understanding of how the <a href=\"https:\/\/cssdeck.com\/blog\/\/css-tips-outline-vs-border\/\">border property<\/a> works for even the most novice of developers to start making shapes quickly and easily.<\/p>\n<p>In this tutorial, we&#8217;re going to show you how to get the ball rolling and create some fun, basic shapes.<\/p>\n<p>The first shape we&#8217;ll make is the easiest: the square.<\/p>\n<p>To start, you&#8217;ll need an empty div with the class &#8220;square&#8221;:<\/p>\n<pre>&lt;div class=\"square\"&gt;&lt;\/div&gt;<\/pre>\n<p>To make the square, you&#8217;ll need your CSS to look like this:<\/p>\n<pre>.square{\r\n width: 150px;\r\n height: 150px;\r\n background: #fc9f5b;\r\n }<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2243 aligncenter\" alt=\"Screen Shot 2017-02-20 at 2.59.19 PM\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-2.59.19-PM.png\" width=\"322\" height=\"318\" srcset=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-2.59.19-PM.png 322w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-2.59.19-PM-300x296.png 300w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-2.59.19-PM-180x177.png 180w\" sizes=\"(max-width: 322px) 100vw, 322px\" \/><\/p>\n<p>In order to create a square, your div has to have a height and width of equal values. If they have different values, then you&#8217;ve got yourself a rectangle. The background color, as always, is up to you.<\/p>\n<p>Next, let&#8217;s create a circle. Creating a circle is pretty much exactly the same as creating a square, only with one extra line of code. Just like creating any other shape, we&#8217;ll start with an empty div.<\/p>\n<pre>&lt;div class=\"circle\"&gt;&lt;\/div&gt;<\/pre>\n<p>Your CSS for the circle will be exactly the same as it was for the square, only with the addition of the line border-radius: 100%.<\/p>\n<pre>.circle{\r\n width: 150px;\r\n height: 150px;\r\n border-radius: 100%;\r\n background: #7de2d1;\r\n }<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2244 aligncenter\" alt=\"Screen Shot 2017-02-20 at 3.02.18 PM\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.02.18-PM.png\" width=\"320\" height=\"318\" srcset=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.02.18-PM.png 320w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.02.18-PM-150x150.png 150w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.02.18-PM-300x298.png 300w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.02.18-PM-180x178.png 180w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/p>\n<p>The addition of the border radius property rounds all the corners to create a circular shape. Just like with the square, it&#8217;s really important that the width of the div is the same value as the height, otherwise you&#8217;ll end up with an oval rather than a perfect circle. The values can be whatever you like and can be as big or as small as you want, they just have to equal each other.<\/p>\n<p>The last shape we&#8217;re going to create in part I of this tutorial is a little more complicated: the triangle. To build a triangle takes a bit more code than the first two examples, and involves the left, right, and bottom border properties.<\/p>\n<p>Again, let&#8217;s start with an empty div:<\/p>\n<pre>&lt;div class=\"triangle\"&gt;&lt;\/div&gt;<\/pre>\n<p>Now it&#8217;s time for the CSS:<\/p>\n<pre>.triangle{\r\n width: 0;\r\n height: 0;\r\n border-left: 125px solid transparent;\r\n border-right: 125px solid transparent;\r\n border-bottom: 200px solid #ff4365;\r\n}<\/pre>\n<p>To make the shape, we&#8217;ve got to give our div a width and height of 0. The size of the left and right borders are what determines the height of the triangle, while the bottom border determines the width. Make sure to remember to give the left and right borders a color value of transparent, otherwise you&#8217;ll end up with a square or a rectangle.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-2245 aligncenter\" alt=\"Screen Shot 2017-02-20 at 3.10.35 PM\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.10.35-PM.png\" width=\"360\" height=\"300\" srcset=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.10.35-PM.png 514w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.10.35-PM-300x249.png 300w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-20-at-3.10.35-PM-180x149.png 180w\" sizes=\"(max-width: 360px) 100vw, 360px\" \/><\/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>In CSS, it&#8217;s relatively easy and fairly common to use div elements to create different recognizable shapes. All it takes is one div element, a little (sometimes a lot, depending on the desired shape) CSS, and usually a basic understanding [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/css-basics-how-to-make-shapes-part-i\/\" title=\"Click to read 'CSS Basics: How to Make Shapes, Part I'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":2244,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[41,6,36,42],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2242"}],"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=2242"}],"version-history":[{"count":1,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2242\/revisions"}],"predecessor-version":[{"id":2246,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/2242\/revisions\/2246"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/2244"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=2242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=2242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=2242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}