Quick CSS problem

Associate
Joined
15 Jun 2009
Posts
440
Location
Cheshire
Looking for some help creating a 1 column #div which centres itself and is as wide as the content put inside (Which is variable)
(In this case an image inserted dynamically).

Anyone know a quick bit off css to sort that?
 
A div is a block level element so by default it will always go as wide as it can within its' container. The solution to this is to put display: inline-block on it, however this means you can't use margin: 0 auto to align it centrally.

Long story short, you must have a block level element with a set width to be able to align centrally.

Do you have a link to the site? If I could see how the rest of the site is laid out there may be a way to do it.
 
Don't believe there's a css solution to this problem.

As above, describe more accurately what is going inside the div that changes it widths. Possible javascript solution.
 
Last edited:
Back
Top Bottom