+ 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
3 Answers
+ 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!