CSS HTML

[ Solved – 5 Answers] Center image using text-align center?

[solved - 5 Answers] CSS - text-align center - The problem is the good way to center an image using css ?Is the property text-align: center;

PROBLEM :

The problem is the good way to center an image using css ?

Is the property text-align: center;

CSS Code
img {
 text-align: center;
}

SOLUTION 1 :

That will not work as the text-align property applies to block containers, not inline elements, and img is an inline element.

Use this instead:

CSS Code
img. Center {
    display: block;
    margin: 0 auto;
}

SOLUTION 2 :
This solution doesn’t always work. if it doesn’t, try.

we tried the following solution.

CSS Code
img {
    display: block;
    margin: 0 auto;
}

SOLUTION 3 :
Another way of doing would be centering an enclosing paragraph.
text-align center is a good way to center an image, and did not specify that the property had to be a part of the img tag.

HTML Code
<p style="text-align:center"><img src="..."/></p>

SOLUTION 4 :
You can do the following solution: text-align:

HTML Code
<center><img src="..." /></center>

SOLUTION 5 :
Here the solution is simply change parent align.
Try this one on parent properties text-align:center

READ  [10 Solved Answer]How to vertically center text with CSS

About the author

Venkatesan Prabu

Venkatesan Prabu

Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.

Add Comment

Click here to post a comment