Maintaining Align | Sololearn: Learn to code for FREE!


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:

2/3/2018 4:31:56 PM


3 Answers

New Answer


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


Not at all😊


It worked - thank you!