Home >Web Front-end >CSS Tutorial >How to Horizontally Center an Image Inside a Div?
Aligning an Image Horizontally within a Div Container
Question:
How to achieve horizontal alignment for an image that resides within a div container element?
Details:
The HTML and CSS code provided includes the necessary structure for the container and image elements, but the image remains uncentered.
Solution:
To effectively center the image horizontally, apply the following CSS rule to the image:
#artiststhumbnail a img { display:block; margin:auto; }
This adjustment ensures that the image is set to display as a block element, enabling margin application. Subsequently, the auto margin setting instructs the browser to automatically calculate and apply equal left and right margins, thus centering the image.
Visual Confirmation:
To demonstrate this solution, visit: http://jsfiddle.net/marvo/3k3CC/2/
The above is the detailed content of How to Horizontally Center an Image Inside a Div?. For more information, please follow other related articles on the PHP Chinese website!