How to center a (background) image within a div?

oompahloompah picture oompahloompah · Feb 18, 2011 · Viewed 245.6k times · Source

Is it possible to center a background image in a div? I have tried just about everything - but no success:

<div id="doit">
  Lorem Ipsum ...
</div>

//CSS
#doit { background-image: url(images/pic.png); background-repeat: none; text-align: center; }

Is this possible?

Answer

Lucas picture Lucas · Feb 18, 2011
#doit {
    background: url(url) no-repeat center;
}