{"id":3068,"date":"2017-06-12T13:13:32","date_gmt":"2017-06-12T18:13:32","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=2325"},"modified":"2017-06-12T13:13:32","modified_gmt":"2017-06-12T18:13:32","slug":"how-to-use-css3s-right-and-left-properties","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/how-to-use-css3s-right-and-left-properties\/","title":{"rendered":"How to Use CSS3&#8217;s Right and Left Properties"},"content":{"rendered":"<p>In CSS, the right and left properties can be used to define the space between the right or the left edge of an element and it&#8217;s nearest ancestor. If you&#8217;re familiar with the margin property, then it might help you to know that in CSS, the right and left properties can be used much the same way in that the margin-right and margin-left properties are used, with a few notable differences.<\/p>\n<p>Unlike with the margin-right and margin-left properties, the right and left properties only work when the element that they&#8217;re applied to has a positioning property value of something other than static (this is the default), so the position of the element must be set to either absolute, fixed, or relative in order for the right or the left property to have any effect on the element.<\/p>\n<p>In terms of syntax, the right and left properties are pretty straightforward and easy to use. They accept property values in fixed values, like px or em, or percentages, and the bigger value you use, the more space you&#8217;re placing between the right or left edges of your elements and their nearest positioned ancestors. With right and left, you can also use negative values, which is an interesting way to use the properties to play with layouts or element positioning.<\/p>\n<p>To see an example of how you might use the properties in context, take a look at the code snippet below:<\/p>\n<pre>div.first{\n\u00a0 \u00a0 right: 10px;\n\u00a0 \u00a0 position: absolute;\n}<\/pre>\n<p>In the example above, we&#8217;re placing 10px of space in between the right side of the div and it&#8217;s nearest ancestor. Notice how we also included the position property so that the right property would perform as intended.<\/p>\n<pre>div.second{\n\u00a0 \u00a0 left: -30px;\n\u00a0 \u00a0 position: relative;\n}<\/pre>\n<p>In the second example, we demonstrated how to use the left property and we even gave it a negative value, so that it&#8217;s actually removing space between the left side of the div in question and its nearest ancestor. Using negative values like this can cause elements to overlap, so proceed with caution when using this type of value, and don&#8217;t overdo it.<\/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, the right and left properties can be used to define the space between the right or the left edge of an element and it&#8217;s nearest ancestor. If you&#8217;re familiar with the margin property, then it might help you [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/how-to-use-css3s-right-and-left-properties\/\" title=\"Click to read 'How to Use CSS3&#8217;s Right and Left Properties'\">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":[173,174,175],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3068"}],"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=3068"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3068\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}