kurt.santo Posted January 23, 2008 Share Posted January 23, 2008 I know how to middle align a div (bottom:0; margin-bottom:auto; top:0; margin-top:auto; height:auto; position:absolute;) or how to center (width:xxx;margin-left:auto;margin-right:auto;), but how do you combine the two? Any suggestions appreciated. Kurt Link to comment Share on other sites More sharing options...
jlhaslip Posted January 24, 2008 Share Posted January 24, 2008 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 More sharing options...
kurt.santo Posted January 24, 2008 Author Share Posted January 24, 2008 This works well. Cheers, mate!Kurt Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.