image-rendering

CSS image-rendering Property

The image-rendering property sets an image scaling algorithm.

By default, each browser will apply to aliasing to the scaled image to prevent distortion, but a problem can arise if you want to keep the original pixelated form of the image.

Sometimes, you can combine the crisp-edges a pixelated values of the image-rendering property, for providing them some fallback for each other.

类目类目
Initial Valueauto
Applies toAll elements.
InheritedYes.
AnimatableDiscrete.
VersionCSS3
DOM Syntaxobject.style.imageRendering = “pixelated”;

Syntax

Syntax

image-rendering: auto | crisp-edges | pixelated | initial | inherit;

Example of the image-rendering property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .pixelated {
        image-rendering: pixelated;
      }
      .resize {
        width: 45%;
        clear: none;
        float: left;
      }
      .resize:last-of-type {
        float: right;
      }
      .resize img {
        width: 100%;
      }
      img {
        margin-bottom: 20px;
        width: 100%;
      }
      .original img {
        width: 20%;
      }
      body {
        background-color: #ccc;
        padding: 20px;
      }
    </style>
  </head>
  <body>
    <h2>Image-rendering property example</h2>
    <div class="original">
      <p>Original image size:</p>
      <img src="/uploads/media/default/0001/02/2895884641188df105fa653fee0b33c785dd7b3d.png" alt="w3cdoc logo" />
    </div>
    <div class="resize">
      <p><code>image-rendering: auto</code></p>
      <img src="/uploads/media/default/0001/02/2895884641188df105fa653fee0b33c785dd7b3d.png" alt="w3cdoc logo" />
    </div>
    <div class="resize">
      <p><code>image-rendering: pixelated</code></p>
      <img class="pixelated" src="/uploads/media/default/0001/02/2895884641188df105fa653fee0b33c785dd7b3d.png" alt="w3cdoc logo" />
    </div>
  </body>
</html>

Result

Values

Values

ValueDescription
autoA standard algorithm maximizing the appearance of an image. This is the default value of this property.
crisp-edgesThe values of the image is preserved without smoothing or blurring.
pixelatedThe browser preserves its pixelated style by using nearest-neighbour scaling.
initialMakes the property use its default value.
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部