What is the best way to center an html element inside its containing element?

Let's say you have the following code snippet:

<div id="container">
  <someelement>This is any element.</someelement>
</div>

What better CSS could I use to horizontally center "someelement" inside its containing div?

+5
source share
3 answers

<someelement> ( : inline), text-align: center . <someelement> - , auto ( , ). , , , IE 5.5 .

+5

JaredPar , , ;)

#container {
    text-align: center;
}

#container someelement {
    margin: 0 auto;
    text-align: left;
}
+11

Try

<someelement style="margin-left:auto;margin-right:auto">This is any element</someelement>
+2
source

All Articles