- #1
kolleamm
- 477
- 44
The following code works successfully and centers my image on the page (CSS)
#box {
display: block;
margin: 0 auto;
}
This one does not (CSS)
img {
display: block;
margin: 0 auto;
}
HTML
<div id="box">
<img src="title.png" style="width:40%">
</div>
I'm confused why it doesn't work. The HTML code stays the same in both cases. Why do I have to use img and not use the box id in the CSS code?
Thanks in advance!
#box {
display: block;
margin: 0 auto;
}
This one does not (CSS)
img {
display: block;
margin: 0 auto;
}
HTML
<div id="box">
<img src="title.png" style="width:40%">
</div>
I'm confused why it doesn't work. The HTML code stays the same in both cases. Why do I have to use img and not use the box id in the CSS code?
Thanks in advance!