Home >Web Front-end >CSS Tutorial >How Can I Horizontally Center an Image Inside a Div Using CSS?
Centering an Image Horizontally Within a Div Element
Issue:
Aligning an image horizontally within its containing div using CSS initially proved challenging. Attempts to center the image using existing CSS failed to produce the desired result.
Solution:
To effectively center the image, a modification to the CSS was implemented:
#artiststhumbnail a img { display:block; margin:auto; }
Result:
This revised CSS ensures that the image within the div element is now perfectly centered horizontally, as desired. A live demonstration can be found here: http://jsfiddle.net/marvo/3k3CC/2/.
The above is the detailed content of How Can I Horizontally Center an Image Inside a Div Using CSS?. For more information, please follow other related articles on the PHP Chinese website!