cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <figure class="full-figure">
<div class="img-row">
<img class="text-image" src="https://jakearchibald.com/static/posts/svg-canvas-media-queries/text.941f43fc7ea8.svg" width="150" height="60">
<canvas width="150" height="60" class="text-canvas"></canvas>
<canvas width="150" height="60" class="text-canvas-sharp" style="width: 150px; height: 60px;"></canvas>
</div>
<figcaption>&lt;img&gt;, &lt;canvas&gt;, умноженный &lt;canvas&gt;. Без умножения, холст будет выглядеть размытыми на экранах высокой плотности</figcaption>
</figure>
            
          
!
            
                 .text-canvas,
  .text-canvas-sharp {
    display: block;
    margin: 0 auto;
  }

@media screen and (min-width: 530px) {
  .full-figure {
      margin-left: 0;
      margin-right: 0;
  }
}
.full-figure {
    margin: 1em 0px;
    overflow: hidden;
    background: #eee;
}

.img-row {
    display: flex;
    align-items: center;
    padding: 30px 0;
    flex-flow: row wrap;
}

.full-figure img, .full-figure iframe, .full-figure video, .full-figure object {
    display: block;
    margin: 0 auto;
}


@media screen and (min-width: 530px) {
  .full-figure>figcaption {
      padding: 6px 10px;
  }
}
.full-figure>figcaption {
    font-size: 0.8rem;
    line-height: 1.4;
    background: #FFE454;
    color: #000;
    padding: 6px 20px;
}
 
            
          
!
            
              function loadImg(url, width, height) {
  return new Promise(function(resolve, reject) {
    var img = new Image();

    if (width) {
      img.width = width;
    }

    if (height) {
      img.height = height;
    }

    img.src = url;
    img.onload = function() {
      resolve(img);
    };
    img.onerror = function() {
      reject(Error('Image load failed'))
    };
  });
}

(function() {
  loadImg('https://jakearchibald.com/static/posts/svg-canvas-media-queries/text.941f43fc7ea8.svg').then(function(img) {
    var canvas = document.querySelector('.text-canvas');
    var context = canvas.getContext('2d');
    context.drawImage(img, 0, 0);
  });
  loadImg('https://jakearchibald.com/static/posts/svg-canvas-media-queries/text.941f43fc7ea8.svg').then(function(img) {
    var canvas = document.querySelector('.text-canvas-sharp');
    canvas.style.width = canvas.width + 'px';
    canvas.style.height = canvas.height + 'px';
    canvas.width = canvas.width * devicePixelRatio;
    canvas.height = canvas.height * devicePixelRatio;
    var context = canvas.getContext('2d');
    context.drawImage(img, 0, 0, canvas.width, canvas.height);
  });
}());

            
          
!
999px
Loading ..................

Console