Welcome to WebmasterWorld Guest from 54.205.75.60

Forum Moderators: not2easy

Message Too Old, No Replies

Is specifying an abolute position better than using margins?

Any advatnages / disadvantages of either technique?

   
9:13 am on Feb 12, 2003 (gmt 0)

10+ Year Member



Is specifying an abolute position better than using margins for positioning elements?
9:39 am on Feb 12, 2003 (gmt 0)

10+ Year Member



i guess by specifyin absolute position, ur formatting might become browser dependent...
am i right?
10:48 am on Feb 12, 2003 (gmt 0)

10+ Year Member



I don't think so, but I'm a newbie to the whole world of css myself. Any experts around please ...
10:54 am on Feb 12, 2003 (gmt 0)

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi vmaster,

I would tend to use absolute positions more often than margins, but it does depend on what exactly is trying to be achieved. For a liquid layout, margins are quite important, but for positioning an element on a page, an absolute position is more accurate.

10:58 am on Feb 12, 2003 (gmt 0)

10+ Year Member



In my opinion it's best to use margins and padding to position elements on the page. This makes it easier to create a liquid layout that will flow to fit various browser window sizes.

It's good practice to try out methods for yourself on dummy pages until you find something that works for you, before you dive into your project for real.

12:27 pm on Feb 12, 2003 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I agree that this is dependent on what you are trying to achieve.

I inherited one site that had over 50 separate elements on a page, all positioned absolutely relative to the BODY element. What a labor that page builder must have gone through finding all those x,y cordinates! But the page was almost all images and it made a kind of sense to put the slices together that way.

A more liquid layout -- one that uses padding, margins, etc -- has proved the most practical for me so far. Absolute positioning on a grand scale tends to buld up the size of the code. You need either a separate ID for each element or you need inline style attributes for each element, and it can create a maintenance hell.

Plus, if there is text involved, a user stylesheet override could cause a major mess.

12:51 pm on Feb 12, 2003 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Agree with the others on the 'depends what you're doing' front.

Personally I lean toward a mixture of the two. I like to absolutely position elements like left/right navigation and then give the content area margin/padding to compensate for the space taken by the nav element.

This creates a semi-fluid design with one or two elements fixed and the rest liquid.

Nick

12:54 pm on Feb 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use absolute positioning for fluid type layouts, though.

div.left{
position: absolute;
top: 0px;
left: 0px;
width: 20%;
}
div.right{
position: absolute;
top: 0px;
left: 20%
width: 60%;
}
div.mid{
position: absolute;
top: 0px;
left: 80%
width: 20%;
}

1:39 pm on Feb 12, 2003 (gmt 0)

10+ Year Member



That's quit clever Birdman. Any specific reason why we've never seen such usage commonly, as it seems to suit my application well.
2:12 pm on Feb 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't really know how many people go that route, but it has worked fairly well for me in a few instances. I believe I used it because it solved margin and padding discrepencies between IE5 and Opera, which is unfortunelately all I test in right now.
2:17 pm on Feb 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, using absolute or mixed(per Nick's post) gives you the ability to present your main content at the top of your HTML doc. Spider food ;)
2:30 pm on Feb 12, 2003 (gmt 0)

10+ Year Member



Birdman, can I suggest an online tool to test how your site would appear in different browsers, or would that be against the terms of the forum. I find it quite useful.
2:42 pm on Feb 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's always that lil' sticky mail route if posting the url in that circumstance is a no-no
2:49 pm on Feb 12, 2003 (gmt 0)

10+ Year Member



Thanks for the suggestion. Never had the need to use sticky mail before. Anyway, since this might be useful for others too, it simply allows you to view your site in ANY BROWSER, and that literally gives away the site address.