Let’s say you have the following chunk of code:
<div id='container'> <someelement>This is any element.</someelement> </div>
What’s the best CSS I could use to horizontally center ‘someelement’ within its containing div?
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.
if your
<someelement>is an inline element (i.e defaults to display: inline) apply text-align: center to its container. If<someelement>is a block element set left and right margin to auto and remember to set a width (block elements default to take all available horizontal space unless a width is stated explicitly). You may have to use both methods if you want it to work in IE 5.5 and below too.