I got a task where i need to center an img element within it’s parent element through CSS. please help how.question
I tried to use the align content property but it didn’t work at all.
I searched online and they said to make the parent element’s text-align to center but that didn’t work too. I am asking this question to solve a question at freecodecamp.org
4
Answers
You can use Flexbox and use property align-items in the center.
Check the flexbox guide – https://css-tricks.com/snippets/css/a-guide-to-flexbox/
v1.
v2. (only vertical)
v3 (use <center> tag)
I also recommend checking these MDN docs, there’s much information about CSS and good examples.
If you have single image, use the margin property.