LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Using Custom Properties to ease Responsive Images Without Browser Reflow.

responsive image

Custom properties --image-width and --image-height are set in the <figure> element, and used in the CSS.

CSS
main {
  width: 80vw;
  margin: 2em auto;
}

figure {
  max-width: var(--image-width);
  margin: 0;
  border: 1px solid #333;
  position: relative;
  padding-bottom: calc((var(--image-height)/var(--image-width))*100%);
}

img {
  display: block;
  max-width: 100%;
  height: auto;
  position: absolute;
}

Description

Inspired by this great post by Jonathan Hollin: https://www.perpetual-beta.org/weblog/responsive-images-without-browser-reflow.html
Term
Fri, 04/20/2018 - 09:14

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv