April 5, 2011

Why does the size of a div element change when changing position from fixed to absolute?

Question by ThiefMaster

I have a div containing some text. This div used to be position:fixed, but for some reasons I need it to be position:absolute.

However, when changing it from fixed to static its size changed (the “auto-sizing” during fixed display was nice and should be preserved).

Here’s a minimal example: http://jsfiddle.net/ThiefMaster/yBRa9/3/

I’m looking for a way to keep position:absolute without the element shrinking to the lowest possible size.

Using JavaScript it’s easy to achieve but if it could be done without additional JS it would be nice.

Answer by Starx

Here Check it. I used a span with inline-block, seems to do what you want (Of course, If I had understood your question properly).

...

Please fill the form - I will response as fast as I can!