{"id":13611,"date":"2011-12-28T07:38:46","date_gmt":"2011-12-28T12:38:46","guid":{"rendered":"http:\/\/info.template-help.com\/?p=13611"},"modified":"2016-11-11T04:01:45","modified_gmt":"2016-11-11T09:01:45","slug":"css-positioning-elements","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/css-positioning-elements.html","title":{"rendered":"CSS. Positioning elements"},"content":{"rendered":"<p>This tutorial will help you learn CSS position properly. <\/p><!--more-->\r\n<p>Position property is usually used to put the element to the required place on the screen. Let&#8217;s see what options we have. <\/p>\r\n\r\n<h4>Static<\/h4>\r\n\r\n<p>HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page.<\/p>\r\n<p>Static positioned elements are not affected by the top, bottom, left, and right properties.<\/p>\r\n<p>There is no need to specify static position in the CSS file unless you need to reset other position value that has been set before. <\/p>\r\n\r\n<pre class=\"brush:css\">\r\n\tdiv.a{\r\n    \tposition:static;\r\n        }\r\n<\/pre>\r\n\r\n<h4>Relative<\/h4>\r\n\r\n<p>A relative positioned element is positioned relative to its normal position. You can affect the position of the element using the &#8220;top&#8221; and &#8220;left&#8221; properties. <\/p>\r\n\r\n<pre class=\"brush:css\">\r\n\tdiv.b{\r\n    \tposition:relative;\r\n        top:20px;\r\n        left:20px;\r\n        }\r\n<\/pre>\r\n\r\n<a href=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2011\/12\/css-positions-1.jpg\"><img loading=\"lazy\" src=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2011\/12\/css-positions-1-300x214.jpg\" alt=\"\" title=\"css-positions-1\" width=\"300\" height=\"214\" class=\"aligncenter size-medium wp-image-13612\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2011\/12\/css-positions-1-300x214.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2011\/12\/css-positions-1.jpg 700w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\r\n\r\n<p class=\"tip\">The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow.<\/p>\r\n\r\n<p>Relatively positioned elements are usually used as parent blocks for the absolutely positioned ones.<\/p>\r\n\r\n\r\n<h4>Absolute<\/h4>\r\n\r\n<p>An absolute position element is positioned relative to the first parent element that has a position other   than static. If no such element is found, the containing block is &lt;html&gt;<\/p>\r\n\r\n<pre class=\"brush:css\">\r\n\tdiv.c{\r\n    \tposition: absolute;\r\n        top:20px;\r\n        left:20px;\r\n        }\r\n<\/pre>\r\n\r\n<p>The following image displays the behavior of the div with the &#8220;c&#8221; class and absolute position in case it is placed within the div with class &#8220;b&#8221; and relative position<\/p>\r\n\r\n<a href=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2011\/12\/css-positions-2.jpg\"><img loading=\"lazy\" src=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2011\/12\/css-positions-2-300x171.jpg\" alt=\"\" title=\"css-positions-2\" width=\"300\" height=\"171\" class=\"aligncenter size-medium wp-image-13613\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2011\/12\/css-positions-2-300x171.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2011\/12\/css-positions-2.jpg 700w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\r\n\r\n<pre class=\"brush:html\">\r\n\t&lt;div class=&quot;b&quot;&gt;\r\n\t\t&lt;div class=&quot;c&quot;&gt;&lt;\/div&gt;\r\n\t&lt;\/div&gt;\r\n<\/pre>\r\n\r\n<p>Below you can see the case when the absolutely positioned element doesn&#8217;t have any relatively positioned one. <\/p>\r\n\r\n<a href=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2011\/12\/css-positions-3.jpg\"><img loading=\"lazy\" src=\"http:\/\/info.template-help.com\/wp-content\/uploads\/2011\/12\/css-positions-3-300x150.jpg\" alt=\"\" title=\"css-positions-3\" width=\"300\" height=\"150\" class=\"aligncenter size-medium wp-image-13614\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2011\/12\/css-positions-3-300x150.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2011\/12\/css-positions-3.jpg 700w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\r\n\r\n<h4>Fixed<\/h4>\r\n\r\n<p>An element with fixed position is positioned relative to the browser window. It will not move even if the window is scrolled<\/p>\r\n\r\n<pre class=\"brush:css\">\r\n\tdiv.c{\r\n    \tposition: fixed;\r\n        top:20px;\r\n        left:20px;\r\n        }\r\n<\/pre>\r\n\r\n<p class=\"tip\">Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist.<\/p>\r\n\r\n<p>You can learn more about the elements positioning from the following <a href=\"http:\/\/www.w3schools.com\/css\/css_positioning.asp\" target=\"_blank\">article<\/a><\/p> \r\n<p>Don&#8217;t forget to review our <a href=\"https:\/\/www.templatemonster.com\/admin-templates.php\" title=\"Bootstrap Admin Themes\" target=\"_blank\">Bootstrap Admin Themes<\/a> based and find out more about CSS functionality.<\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial will help you learn CSS position properly.<\/p>\n","protected":false},"author":2,"featured_media":13615,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[256,253],"tags":[1125,514,1127,667,1126,693],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/13611"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=13611"}],"version-history":[{"count":0,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/13611\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media\/13615"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=13611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=13611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=13611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}