views:

737

answers:

4

I am watching the ASP.NET learn video on http://www.asp.net/learn/3.5-videos/video-13.aspx and it is showing you can place controls on a page using Absolute positioning. I am just wondering if this is a best practice or should I avoid Absolute positioning? It seems like a nice, easy feature, but there must be some reason why it is not selected by default in the VS IDE.

A: 

Absolute positioning is a mess. Don't use it for most positioning. Consider if you have an absolutely positioned div inside of another absolutely positioned div, and you move the outer one, then you haven't moved the inner one.


Microsoft sometimes does things to make it easier for beginners. Absolute positioning was pushed heavily in .NET 1.0. I think it may even have been the default. That was back in the day when there were fewer web developers in the world, and it was assumed that most ASP.NET developers were VB6 Forms developers, who would find relative positioning very foreign.

Of course, they now understand why this was a bad idea. They even seem to have learned why we don't all like Web Site pseudo-projects: in VS2005, they removed Web Application Projects, apparently because they thought they were too complicated for the new web developers they wanted to target. They quickly heard that this was a mistake, and corrected it very quickly, in VS2005 SP1 (one of the fastest service packs I've ever seen from Microsoft).

John Saunders
so do you use tables for positioning of controls?
MedicineMan
@MedicineMan nop, you use css for positioning.
eglasius
This is incorrect. Absolute positioning works relative to positioned parents, so moving the parent element WILL move the child element as well.
jvenema
I believe you are incorrect. Absolute means absolute with respect to the window.
John Saunders
Sorry John, but you're wrong. Check it and see. Also, here's the w3c ref: http://www.w3.org/TR/CSS2/visuren.html#choose-position. As you'll notice, they point out:"These properties specify offsets with respect to the box's containing block."Which is not necessarily the window.
jvenema
You're right. I just checked.
John Saunders
+3  A: 

Many users change the font size of your page by configuring their browser settings. If you use absolute positioning, things will not align right for them.

In absolute positioning, when your page gets more complex, a single design decision would require you to reposition all of the elements, but in relative positioning, you would only need to change one value, and all the other elements would adjust accordingly.

Gudmundur Orn
+1 I agree, although this doesn't mean absolute positioning has no use at all - see my answer
eglasius
I think you mean 'static' positioning would adjust elements accordingly. Relative positioning would place everything in normal flow first, then move elements out of place.
Bryan M.
+1  A: 

Absolute positioning takes the element out of the flow of the document. This means that it will no longer align with other elements. There are very good reasons to do this sometimes but generally you want to avoid it.

ASP.NET is notorious for using bad HTML/CSS practices. This framework is designed for 'rapid development' not 'elegant, web standards development.

Matthew James Taylor
While this is correct to some degree, you're misrepresenting how absolute positioning works. Since its absolute RELATIVE to its positioned parent, it certainly can still line up with other elements. You need to be careful, certainly, but it is very useful, and well supported across browsers.
jvenema
A: 

I think this question is more about css than the visual studio. Because of the reasons explained in other answers, you should use relative positioning where possible.

This doesn't mean absolute positioning has no use at all. Check out http://csszengarden.com/, to see how you can use a simple html structure and still use some really interesting designs.

eglasius