I just began my first project and am trying to center an image in it. I have looked on a few websites and searched through the freecodecamp projects I have previously completed and can’t find anything that will work.
Here is my code so far:
<h1 class="green-text text-center">Karl Marx</h1>
<a href="#"><img class="smaller-image" src='//discourse-cloud-file-uploads.s3.dualstack.us-west-2.amazonaws.com/freecodecamp/original/3X/8/c/8cb74b7339564360d451b4f3484be5340d0da18f.jpg'></a>
You might want to look into margin, or text center
btw, you’re missing a closing bracket and the declarations should not really be in one line unless minimized for production purposes
You should add
text-align: center to the container of the img tag. This will center it horizontally.
try placing a center element right before the image element and remember to close it.
I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (
</>) will also add backticks around text.