donald
Members
-
Joined
-
Last visited
Reputation Activity
-
donald reacted to bocaj in middle div center problemThe easiest way to center it would be like so,
div#header{position:relative} #telephone{ position:absolute; left:50%; margin-left: >> Enter exactly half the width of the image here, as a negative number << ; }
Effectively, it works like so:
Position:absolute allows you to specify an exact placement within a position container, hence the need for position:relative.
Left:50% will position the left side of the object dead center, however we need the center of the object to be dead center, so we need to pull the left half of the image across until the center falls where we need it.
I hope the explanation helps a little, it's a tricky concept to begin with, but centring elements is commonly needed.
I didn't have the dimensions of the telephone image, hence why i haven't put a number in.