Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS for aligning image in the center

Tags:

css

wordpress

I have an image placed in a widget on my WordPress blog. I want the image to be centered since it's smaller than the sidebar it is placed in.

I currently use the following code:

<img style="display: block; margin-left: auto; margin-right: auto; padding-bottom: 10px; width: 150px; height: 155px;" src="path">

But the image aligns left.

What am I doing wrong?

Many thanks!

like image 903
Laura Avatar asked Oct 28 '15 09:10

Laura


1 Answers

Try margin: 0 auto instead of declaring them separately. Also you can try adding text-align: center to to it's container or parent div

like image 117
Mike Smith Avatar answered Nov 24 '22 01:11

Mike Smith