{"id":894,"date":"2010-09-16T03:06:58","date_gmt":"2010-09-16T03:06:58","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=894"},"modified":"2010-09-16T03:09:41","modified_gmt":"2010-09-16T03:09:41","slug":"what-are-the-differences-between-absolute-and-relative-positioning","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2010\/09\/what-are-the-differences-between-absolute-and-relative-positioning\/","title":{"rendered":"What are the differences between absolute and relative positioning?"},"content":{"rendered":"<h2>Absolute<\/h2>\n<p>This is a very powerful type of positioning that allows you to literally place any page element exactly where you want it. You use the positioning attributes top, left bottom and right to set the location. Remember that these values will be relative to the next parent element with relative (or absolute) positioning. If there is no such parent, it will default all the way back up to the   element itself meaning it will be placed relatively to the page itself.<\/p>\n<p>Most important thing about absolute positioning is that these elements are removed from the flow of elements on the page. An element with this type of positioning is not affected by other elements and it doesn\u2019t affect other elements. This is a serious thing to consider every time you use absolute positioning.<\/p>\n<pre lang=\"html\">\r\n<html>\r\n<head>\r\n<style type=\"text\/css\">\r\nh2\r\n{\r\nposition:absolute;\r\nleft:100px;\r\ntop:150px;\r\n}\r\n<\/style>\r\n<\/head>\r\n\r\n<body>\r\n<h2>This is a heading with an absolute position<\/h2>\r\n<p>With absolute positioning, an element can be placed anywhere on a page. The heading below is placed 100px from the left of the page and 150px from the top of the page.<\/p>\r\n<\/body>\r\n<\/html>\r\n<\/pre>\n<h2>Relative<\/h2>\n<p>This type of positioning is probably the most confusing and misused. What it really means is \u201crelative to itself\u201d.<br \/>\nA relative positioned element is positioned relative to its normal position. The content of a relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow.<br \/>\nRelatively positioned element are often used as container blocks for absolutely positioned elements.<br \/>\nexample &#8211;<\/p>\n<pre lang=\"html\">\r\n<html>\r\n<head>\r\n<style type=\"text\/css\">\r\nh2.pos_top\r\n{\r\nposition:relative;\r\ntop:-50px;\r\n}\r\n<\/style>\r\n<\/head>\r\n\r\n<body>\r\n<h2>This is a heading with no position<\/h2>\r\n<h2 class=\"pos_top\">This heading is moved upwards according to its normal position<\/h2>\r\n<p><b>Note:<\/b> Even if the content of the relatively positioned element is moved, the reserved space for the element is still preserved in the normal flow.<\/p>\r\n<\/body>\r\n<\/html>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Absolute This is a very powerful type of positioning that allows you to literally place any page element exactly where you want it. You use the positioning attributes top, left bottom and right to set the location. Remember that these values will be relative to the next parent element with relative (or absolute) positioning. If [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[28],"tags":[],"class_list":["post-894","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=894"}],"version-history":[{"count":4,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/894\/revisions"}],"predecessor-version":[{"id":896,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/894\/revisions\/896"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}