Home  >  Article  >  Web Front-end  >  How to Center a Cropped Image Horizontally with CSS?

How to Center a Cropped Image Horizontally with CSS?

DDD
DDDOriginal
2024-10-26 08:41:30791browse

How to Center a Cropped Image Horizontally with CSS?

Centering an Image Horizontally with CSS

In an effort to display only a portion of an image, you're using the clip() property to crop it. However, after cropping, you're experiencing difficulty centering the image.

To resolve this, implement the following CSS:

<code class="css">.center img {        
  display:block;
  margin-left:auto;
  margin-right:auto;
}</code>

Next, add class="center" to your image to achieve horizontal centering:

<code class="html"><div id="loading" class="loading-invisible">  
    <img class="loading center" src="logo.png">
</div></code>

With these modifications, your image should now be centered horizontally despite the cropping.

The above is the detailed content of How to Center a Cropped Image Horizontally with CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn