September 13, 200917 yr Hi all, I am looking to align a table or an image in the middle of a web page. So no matter what resolution the viewer is using, or no matter if the page is resized, the image/table stays dead centre of the page, does that make sense and is it possible? thanks
September 13, 200917 yr CSS: #center { position: absolute; width: 300px; height: 200px; left: 50%; margin-left: -150px; top: 50%; margin-top: -100px; } HTML markup:- <img id="center" src="image.jpg" alt="image description"> The negative margins are always half the element size. You can do the same with a table. It works best with small widths and heights. If someone looks at it in a small window and the element is wider than the window the left side will disappear out to the left where you can't scroll to see it. Similarly if the height is too large it will disappear up over the top of the window. See http://www.wickham43.net/centerphotolink.php
Create an account or sign in to comment