{"id":4584,"date":"2008-03-11T12:03:00","date_gmt":"2008-03-11T12:03:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2008\/03\/11\/absolute-and-relative-positioning-in-visual-web-developer-2008-designer\/"},"modified":"2008-03-11T12:03:00","modified_gmt":"2008-03-11T12:03:00","slug":"absolute-and-relative-positioning-in-visual-web-developer-2008-designer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/absolute-and-relative-positioning-in-visual-web-developer-2008-designer\/","title":{"rendered":"Absolute and relative positioning in Visual Web Developer 2008 designer"},"content":{"rendered":"<p>Design view in&nbsp;Visual Studio and Visual Web Developer Express&nbsp;2008&nbsp;provides several tools that help with absolute and relative positioning of controls. I&#8217;d like to describe how do they work and what kind of visual hints the designer provides.<\/p>\n<p>How do I set my control position to absolute? Use Format | Position menu:<\/p>\n<p><img decoding=\"async\" title=\"Format menu\" alt=\"Format menu\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/FormatMenu.png\" border=\"1\">&nbsp;<\/p>\n<p>Unfortunately, because of a bug, the menu is disabled for &lt;span&gt; and &lt;a&gt; based controls. To enable the menu, add style=&#8221;display:block&#8221; to labels or hyperlinks. This will be fixed in the next service pack. You can then use the Position dialog to set positioning mode:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/PositionDialog.png\">&nbsp;<\/p>\n<p>In most cases you&#8217;ll want <a class=\"\" href=\"http:\/\/reference.sitepoint.com\/css\/absolutepositioning\" target=\"_blank\" rel=\"noopener\">absolute positioning<\/a>. After setting the position you should be able to&nbsp;move the&nbsp;control around. There are two ways you can move the control:<\/p>\n<p><img decoding=\"async\" title=\"Dragging the control\" height=\"594\" alt=\"Dragging the control\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/DragMethods.png\" width=\"792\" border=\"1\"><\/p>\n<p>Watch the status bar, it provides hints about&nbsp;various options you have in moving and resizing&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Status bar\" height=\"546\" alt=\"Status bar\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/StatusBar.png\" width=\"1075\" border=\"1\"><\/p>\n<p>Designer also provides visual cues to which element is control&#8217;s positioning container.&nbsp;This is important to know since absolute positioning in CSS does not work the same way it works in Windows Forms. Controls are not always positioned relatively to their immediate parents. Instead, they are positioned relatively to their <a class=\"\" title=\"Containing block description\" href=\"http:\/\/reference.sitepoint.com\/css\/containingblock\" target=\"_blank\" rel=\"noopener\">containing block<\/a>. For absolutely positioned controls that would be the nearest ancestor that has position attribute set in its style or a body element. When you select absolutely positioned control, designer display four guides and highlights the positioning contaner.<\/p>\n<p><img decoding=\"async\" height=\"611\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/AbsoluteInDiv.png\" width=\"807\" border=\"1\"><\/p>\n<p>Here is an example when element is in a div, but is positioned by another, outer&nbsp;div<\/p>\n<p><img decoding=\"async\" height=\"722\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/AbsoluteInInnerDiv.png\" width=\"793\" border=\"1\">&nbsp;<\/p>\n<p>In this example button appears to be in &lt;div&gt;, while, in fact, it is in the &lt;body&gt; element.&nbsp;&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"592\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/AbsoluteInBody.png\" width=\"794\" border=\"1\">Designer also supports <a class=\"\" href=\"http:\/\/reference.sitepoint.com\/css\/relativepositioning\" target=\"_blank\" rel=\"noopener\">relative positioning<\/a>. Relative positioning is tricky though. It is&nbsp;not relative to the parent control. Instead,&nbsp;relative position describes shift of the element from its normal position in the layout. <\/p>\n<p>&nbsp;<img decoding=\"async\" height=\"611\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/RelativeInText.png\" width=\"807\" border=\"1\"><\/p>\n<p>As you can see, if element is relatively positioned, designer only draws two guides instead of four. Although rendering seems odd, this is exactly how FireFox renders the page:<\/p>\n<p><img decoding=\"async\" height=\"472\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/RelativeInText-FireFox.png\" width=\"731\">&nbsp;<\/p>\n<p>Unfortunately, IE7 does not render the page same way FireFox and Visual Studio 2008 Web designer do:<\/p>\n<p><img decoding=\"async\" height=\"510\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/RelativeInText-IE7.png\" width=\"792\">&nbsp;<\/p>\n<p>In order to help with element alignment, designer provides a grid, ruler and ability to snap element position to the grid. You can activate this functionality in Tools | Options<\/p>\n<p><img decoding=\"async\" height=\"438\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/GridOptions.png\" width=\"757\"><\/p>\n<p>As well as in the View menu<\/p>\n<p><img decoding=\"async\" height=\"741\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2008\/03\/GridMenu.png\" width=\"864\" border=\"1\"><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Design view in&nbsp;Visual Studio and Visual Web Developer Express&nbsp;2008&nbsp;provides several tools that help with absolute and relative positioning of controls. I&#8217;d like to describe how do they work and what kind of visual hints the designer provides. How do I set my control position to absolute? Use Format | Position menu: &nbsp; Unfortunately, because of [&hellip;]<\/p>\n","protected":false},"author":404,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[31,7271,7261,7262,7273,7272,147],"class_list":["post-4584","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-asp-net","tag-css","tag-css-and-html","tag-development","tag-orcas","tag-tips-and-tricks","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>Design view in&nbsp;Visual Studio and Visual Web Developer Express&nbsp;2008&nbsp;provides several tools that help with absolute and relative positioning of controls. I&#8217;d like to describe how do they work and what kind of visual hints the designer provides. How do I set my control position to absolute? Use Format | Position menu: &nbsp; Unfortunately, because of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/4584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/404"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=4584"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/4584\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=4584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=4584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=4584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}