Maintaining Align | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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

3rd Feb 2018, 4:31 PM
luciel
luciel - avatar
3 Respostas
+ 7
Usually I'm using: HTML: <div> <img src="link" alt="description"/> </div> CSS: div { display: block; margin: auto; }
4th Feb 2018, 4:45 PM
renamed
renamed - avatar
+ 7
Not at allšŸ˜Š
4th Feb 2018, 4:56 PM
renamed
renamed - avatar
+ 1
It worked - thank you!
4th Feb 2018, 4:53 PM
luciel
luciel - avatar