align my image in the div

hidrau
hidrau used Ask the Experts™
on
Hello guys,

I am trying many things and now I am lost, then I need a help from you.

I have a purchase image and I want to align it in the center of my div, how can I do this?

this is my page that I am developing

site

thanks
Alex
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
You need to display your image as a block-level element:

<img style="margin-left: auto;margin-right: auto;display:block" alt="" src="images/purchase.jpg">

Open in new window

The auto margins only work on blocks, and by default, an image is inline.

Author

Commented:
hummm, you cleared my mind with your explanation. Thanks a lot Chris.

let me ask you that.

Imagine that I have some text and I'd like to have my image on the left and the text on its right in my div, What should I do ?
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
In that case, you'd need to float your image:

<img style='float:left;' src='...'>

In your page, this probably wouldn't work as it is, because the text content is in a different DIV.

Here's a good intro into floats: https://css-tricks.com/all-about-floats/

Author

Commented:
once again, thanks a lot

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial