Maintaining Align | Sololearn: Learn to code for FREE!

+1

Maintaining Align

I’m trying to center an image while also having it in a div. The issue is, though, when I don’t add height or width properties to the div, it stretches the whole page, but the image is centered. Though when I do apply height and width to the div, the image automatically becomes un-centered and the div stays at the left. How do I center the image AND the div (the div having width and height properties added) without messing with anything else? Code: codepen.io/Technical/pen/yveqPP

2/3/2018 4:31:56 PM

luciel

3 Answers

New Answer

+7

Usually I'm using: HTML: <div> <img src="link" alt="description"/> </div> CSS: div { display: block; margin: auto; }

+7

Not at all😊

+1

It worked - thank you!