Home >Web Front-end >CSS Tutorial >Can you Resize an Image to a Percentage Within a Percentage Using Only CSS?

Can you Resize an Image to a Percentage Within a Percentage Using Only CSS?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-30 22:25:02493browse

Can you Resize an Image to a Percentage Within a Percentage Using Only CSS?

CSS Image Resizing: Achieving Percentages Within Percentages

Resizing an image to a percentage of its original dimensions can seem like a challenge with CSS alone. However, surprisingly, it is possible using two innovative methods.

Method 1: Visual Transformation

This method allows you to visually resize the image without altering its actual dimensions. The resulting image will be centered within its original size.

<code class="css">img {
  transform: scale(0.5);
}</code>

Applying this CSS to an image, such as the placeholder image below, will visually shrink it to 50% of its original size:

<code class="html"><img src="https://via.placeholder.com/300x200" /></code>

The above is the detailed content of Can you Resize an Image to a Percentage Within a Percentage Using Only 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