Skip to content

Instantly share code, notes, and snippets.

@dima-f1
Forked from dbox/Adobe-ask-experts.md
Created November 3, 2015 09:38
Show Gist options
  • Select an option

  • Save dima-f1/d862041a89c89d0bb67e to your computer and use it in GitHub Desktop.

Select an option

Save dima-f1/d862041a89c89d0bb67e to your computer and use it in GitHub Desktop.
Answer for adobe ask the experts

Q: What is your favorite Css 'trick'?

Responsive images in CSS are pretty easy: just set the width: 100% and height: auto and you're good to go. Things get a little unpredictable, though, when dealing with background images. Since putting a height on the element causes lots of responsive headaches, one workaround is to have the container scale by its aspect ratio. This can be achieved by setting a few attributes to the element's :after tag:

.my-element {
  overflow: hidden;
  position: relative;
}
.my-element:after {
  content: "";
  display: block;
  height: 0;
  padding-top: 56.25%; /* Aspect ratio = height divided width times 100 */
}

See a CSS demo, or grab this handy Sass mixin.


Daniel Box
Designer, KNI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment