Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to this site and HTML so sorry if I get this messed up

HTML
<img align="center"src="https://yt3.ggpht.com/-7xOKskOmwVY/AAAAAAAAAAI/AAAAAAAAAAA/7s2wU-RMkac/s100-c-k-no-rj-c0xffffff/photo.jpg" />

I want that image to be in the center of the website. When I align left or center it just goes to the right, and when I align it to the right, it goes to the left. There's text beneath it so I'm guessing maybe it just wraps weird with the text under it? Anyways, some help please.

What I have tried:

I've tried messing with where the picture is on the website but it just doesn't make a difference.
Posted
Updated 25-Mar-16 20:34pm

1 solution

You can use CSS to do this.

In your stylesheet:
CSS
.center {
    display: block;
    margin: 0 auto;
}

Then, give your image the center class using the following attribute:
HTML
class="center"


If you don't want to use a separate stylesheet, you can use the style attribute on the img element to set the styling (using a separate stylesheet is cleaner, though):
style="display: block; margin: 0 auto"

Or you can wrap the image in a p tag with align="center":
HTML
<p align="center">
    <img align="center"src="https://yt3.ggpht.com/-7xOKskOmwVY/AAAAAAAAAAI/AAAAAAAAAAA/7s2wU-RMkac/s100-c-k-no-rj-c0xffffff/photo.jpg" />
</p>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900