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

How to Center a Cropped Image Horizontally with CSS?

DDD
Release: 2024-10-26 08:41:30
Original
875 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template