I’m trying to display an alert when a user clicks a button but can’t figure out how to horizontally center an alert. I’d like the alert to stay within #main. See this fiddle.
thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your markup and CSS positioning is actually wrong, instead of using
position: fixed;useposition: relative;for#mainandposition: absolute;for#messageand also shift your messagedivin#main divAnd about the calculation part, when you want to center a
div, you’ve to givetop: value (-)minus heightof thedivto bring it vertically center..My Fiddle