6 replies [Last post]
sohrabx
Offline
newbie
Last seen: 19 years 32 weeks ago
Joined: 2003-08-19
Posts: 6
Points: 0

I'm reading around on the web, trying to understand the "best practices" of creating css files, and I am now getting the impression that absolute positioning is not the "recommended" way of going about it. If this is the case, why?

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 week 2 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

CSS:Is only using absolute positioning bad, and if so, why?

Hi sohrabx,
Absolute positioning can become a useability issue when users have small browser windows.

Absolutely positioned elements are taken out of the normal document flow, so other items may overlay or clash with them.

It is better to avoid when possible, or at least use with caution. Wink

Hope that helps

sohrabx
Offline
newbie
Last seen: 19 years 32 weeks ago
Joined: 2003-08-19
Posts: 6
Points: 0

I see, but, what if... :)

What you stated makes a lot of sense, I now understand, thank you very much for the reply Smile

just one other addition to my question, it was stated "Absolutely positioned elements are taken out of the normal document flow, so other items may overlay or clash with them.
"

What if you absolute positioned all the elements on your page and made sure that they didn't overlay on each other?

-Sohrab

KnightWolfJK
KnightWolfJK's picture
Offline
Enthusiast
Washington, DC
Last seen: 15 years 40 weeks ago
Washington, DC
Timezone: GMT-5
Joined: 2003-06-10
Posts: 210
Points: 0

CSS:Is only using absolute positioning bad, and if so, why?

I can only see pure absolute positioning working in a few limited instances. The main issue that I see is that anything absolutely positioned is completely dependent on the window size and resolution. Alas, window size and resolution are user-specific and incredibly dynamic in nature, creating an obvious clash.

I mentioned a few limited instances- for example, it would work if you're using small to medium popup windows and can control the window size and restrict window-resizing.

For a more visual example, if you care to track down any links of pure absolutely positioned webpages, I'd be happy to run them through BrowserCam and see how well (if at all) it degrades.

Diplomacy is the art of letting someone have your way

exorcyze
Offline
Regular
Last seen: 19 years 35 weeks ago
Joined: 2003-07-30
Posts: 18
Points: 0

CSS:Is only using absolute positioning bad, and if so, why?

KnightWolf:

I have used absolute positioning on a couple things:
http://mx.coldstorageonline.com/layout2/
http://mx.coldstorageonline.com/hrd/default.htm

The reason I used absolute positioning for these was because then I can have the nav elements at the bottom of the XHTML, which means that people that view it with really old browsers or with stylesheets off get the content first, instead of having to scroll past a ton of navigation items...

That's the main benefit I can see behind using CSS-P...

inababes
inababes's picture
Offline
Regular
Last seen: 19 years 34 weeks ago
Joined: 2003-08-02
Posts: 17
Points: 0

CSS:Is only using absolute positioning bad, and if so, why?

what about using absolute positioning, but using % for div widths so that they fit even in a smaller browser window? i'm using mostly absolute positioning for my site, so tell me if i should be doing something else. Wink

Pob
Offline
Enthusiast
Hampshire UK
Last seen: 11 years 42 weeks ago
Hampshire UK
Timezone: GMT+1
Joined: 2003-08-16
Posts: 60
Points: 5

CSS:Is only using absolute positioning bad, and if so, why?

Hi,

Most sites use a combination of positioning techniques but they do rely on the objective to be acheived.

If you want overlapping elements then you will need absolute (or relative) positioning. If your whole document flows one element after the other then static (the default) is ok.

Pixel perfect layout can be achieved in CSS with a mixture of techniques.
Don't forget you can move static elements by adjusting their margins to position them more precisely.

You can also absolutely place elements in relation to its parent element instead of the viewport. This is achieved by giving the parent a value for the property position other than static. With this technique you could absolutely place an element inside a container that has a fluid width/height and the absolute element will adjust with its parent.

Most of the elements on a page will usually be in the normal flow with some elements absolutely positioned.

However its all down to choice though as mentioned in the posts above the web page is a dynamic medium and it best not to try and control every aspect of your page. With a suitable browser the visitor can change everything about your page from the size of the text and layout to the stylesheets they are going to use. You never know what your visitor is going to view your site on (e.g. hand-held or massive monitor).

It all boils down to making the right choice for you and your audience.

Paul