Image sliced up with photoshop, doesn't want to be centered in my <div>
So, I have an image that I sliced up in photos开发者_如何学JAVAhop and want to add into a that is centered (with dreamweaver). As the picture is 1024px wide and 768px high, I've created a box of that size, setting margins to auto. The in itself is getting centered just fine, and I've pasted the code of the image in there... but the image itself is not getting centered at all ! It stays on the top-left of my webpage !!
I don't exactly understand what I'm doing wrong, so if anybody here as an idea about how to fix this, it would be very useful !
Thanks in advance :)
As others have said, without seeing your code, it's difficult to envisage what's happening. However, it's important to realize that HTML treats images as inline elements. In order to centre an image with CSS, you need to set its display property to block. For example:
img.centered {
display: block;
margin: 0 auto;
}
As long as your tag has a declared width, just apply the centered class to the image, and it will be centered inside its parent element.
For more details, see my article Centering web pages and other elements with CSS.
精彩评论