I want a div to be centered at a certain point instead of the top left of the div being set at a point.
//css code
#div {
margin-left: 50px;
margin-top: 300px;
}
If need be, I’m also using javascript and jquery.
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.
Assuming you have:
<div><div id="div"></div>
</div>
Then this will put the center where the top left corner is.
$('div#div').offset({ top: $('div#div').offset().top-$('div#div').width()/2, left: $('div#div').offset().left-$('div#div').height()/2 });