Hello,
I'm having a vexing problem that's driving me nuts.
Simply, I have a parent div and a single child div within it. In the child div, I would like to insert a single image, however, the image may be larger than the dimensions of the child div. I would like the image to be centred horizontally and vertically. Any help with my code below would be greatly appreciated.
Here's what I have:
HTML:
CSS:
Thanks,
ds.
I'm having a vexing problem that's driving me nuts.
Simply, I have a parent div and a single child div within it. In the child div, I would like to insert a single image, however, the image may be larger than the dimensions of the child div. I would like the image to be centred horizontally and vertically. Any help with my code below would be greatly appreciated.
Here's what I have:
HTML:
Code:
<div id="parent"><div id="child"><img src="image1.jpg" /></div></div>
CSS:
Code:
#parent { /* The parent spans the width of the browser */
width: 100%; height: 305px; background-color: white; display: block;
}
#child { /* The child should fit within the parent and is centred */
width: 960px; background-color: #CCC; border: 1px solid #999; height: 305px; margin: 0 auto;
}
#child img { /* How do I center my image within the child div? My code here doesn't work :( */
display: inline-block; margin: 0 auto; overflow: hidden;
}
Thanks,
ds.