MDanz Posted February 21, 2010 Share Posted February 21, 2010 can i get the correct code to center this div. I've tried margin 0 auto, text-align: center etc but it still stays to the left of the page #layer1 { position: absolute; visibility: hidden; width: 400px; height: 300px; left: 20px; top: 300px; background-color: #000000; border: 1px solid #FBB917; padding: 10px; } Quote Link to comment https://forums.phpfreaks.com/topic/192779-centering-div-on-page-help/ Share on other sites More sharing options...
MDanz Posted February 21, 2010 Author Share Posted February 21, 2010 #layer1 { position: absolute; visibility: hidden; width: 400px; height: 300px; top: 0px; left: 50%; margin-left: 300px; background-color: #000000; border: 1px solid #FBB917; padding: 10px; } this works but when i change screen resolution it won't any help?? Quote Link to comment https://forums.phpfreaks.com/topic/192779-centering-div-on-page-help/#findComment-1015498 Share on other sites More sharing options...
Hybride Posted February 21, 2010 Share Posted February 21, 2010 Don't use absolute positioning for that - it does exactly what it says, absolutely positions the div container, and does not become fluid on the resolution. Removing them should get rid of the problem (and then changing the top/lefts, as those are absolutes). And using "text-align:center" is best in the body{} tags then using a "text-align:left" in your div to align the text left. Quote Link to comment https://forums.phpfreaks.com/topic/192779-centering-div-on-page-help/#findComment-1015708 Share on other sites More sharing options...
haku Posted February 24, 2010 Share Posted February 24, 2010 If you absolutely must use absolute positioning, you can do this: #layer1 { position: absolute; visibility: hidden; width: 400px; left: 50%; margin-left: -200px; } Quote Link to comment https://forums.phpfreaks.com/topic/192779-centering-div-on-page-help/#findComment-1017157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.