Ahmet emre CETIN Ahmet emre CETIN - 1 year ago 123
CSS Question

margin:auto not working with width:auto

enter image description here

I want to first div be center.

margin:auto not working with width:auto.

width value must be auto

<div style="display:block;margin:auto;width:auto">
<div style="background-image:url(assets/img/asd.png) "></div>
<div style="background-image:url(assets/img/abc.png)"></div>
<div style="background-image:url(assets/img/asd.png)"></div>
<div style="background-image:url(assets/img/asd.png)"></div>
</div>

Answer Source

you can't. Obviously you are trying to center these images. Just use this instead:

<div style="text-align: center;">
  <div style="display: inline-block;background-image:url(assets/img/asd.png) "></div>
  <div style="display: inline-block;background-image:url(assets/img/abc.png)"></div>
  <div style="display: inline-block;background-image:url(assets/img/asd.png)"></div>
  <div style="display: inline-block;background-image:url(assets/img/asd.png)"></div>
</div> 

And it would be better to use classes and a stylesheet instead of inline CSS....

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