Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute Positioning Performance

Tags:

css

I have a colleague who uses a lot of absolute positioning in his css.

I find I can usually achieve the same visual effects by providing a different structure to the html - in fact I tend to shy away from using absolute positioning except when I absolutely need to.

Question - are my instincts sound here, other than css complexity, is absolute positioning something to be used sparingly?

like image 290
BonyT Avatar asked Jun 01 '11 16:06

BonyT


People also ask

What does absolute positioning mean?

Absolute positioning defines the position of a given bounding box from the top and left side margins of the web page. This not only allows objects to be placed in an exact location, it also allows objects to be placed one on top of another.

What is an example of absolute position?

When you need something to be positioned in an very specific spot you would use absolute positioning. For instance you may want to have an image with an overlapping caption that always sits at the top of the picture (say 20px from the top).

What does absolute positioning effect?

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.

Should I use absolute positioning?

In some cases, absolute positioning breaks faster and it's better to use floats, while in other situations it's better to use absolute positioning because floats would break the layout. luckily for us, there is one very simple rule: If elements should not interact, use absolute positioning, if they should, use floats.


2 Answers

Excessive use of absolute positioning is a design problem, but it's not so much because of any a performance issues - I don't know of anything performance-wise which would make me hesitate to use absolute positioning when I needed it.

The real problem with absolute positioning everything is that you tend to tie your layout to fixed sizes, which can make things go completely nuts if you have to adjust for things which change size.

For example, what happens if you want to increase the font size of your site? If everything is absolutely positioned, you'll have a huge effort to re-align everything.

In the same vein, absolute positioning almost always means the entire layout is positioned and sized in pixels rather than em units or percent. Again, nothing wrong with using pixel sizing, but it does generate accessibility issues when people try to adjust the site themselves (eg with zoom or a magnifier, or just changing the font sizes, etc)

And have you tried viewing your site on various mobile devices? Sites that are rigidly designed are generally the worst when it comes to viewing on a smaller screen size. Far better to have a fluid design that just works wherever you use it, rather than having to have an entirely separate site for mobiles.

like image 166
Spudley Avatar answered Nov 04 '22 05:11

Spudley


To me, using absolute positioning in relatively-positioned elements (like, within a footer) is time-saving. Using it everywhere could be messy when you have to change a layout (columns, headers...).

like image 31
ecchymose Avatar answered Nov 04 '22 05:11

ecchymose