Jump to content

Center and middle align div


Recommended Posts

View source this page: http://www.jlhaslip.com/samples/misc/posit...entereddiv.htmlThis critical part is the CSS here:

#mydiv {	position:absolute;	top: 50%;	left: 50%;	width:30em;	height:18em;	margin-top: -9em; /*set to a negative number 1/2 of your height*/	margin-left: -15em; /*set to a negative number 1/2 of your width*/	border: 1px solid #ccc;	background-color: #f3f3f3;}

And you need to know the div's width and height in order to centre it accurately.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...