Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                   .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;
}
 
              
            
!

JS

              
                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

Console