Search code examples
htmlcssimagebackgroundcenter

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


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?


Solution

  • #doit {
        background: url(url) no-repeat center;
    }