Ajay Gupta Ajay Gupta - 1 year ago 62
HTML Question

when will margin: auto; work and not work?

Is this an issue in regards to block and inline elements?

It can be frustrating having to use

to center things sometimes.

doesn't work, is using margins the only or best alternative?

Please Any one Explain with an Example (or with Jsfiddle)

Answer Source

margin:auto wont work when you have not set a width or when you have a float. To center a block element you will have to give it a width then only you can use margin: 0 auto. This is for block elements. For inline elements you will have to use text-align:center.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download