background-size contain, but don’t scale up

Unfortunately, what you want to do isn’t possible in CSS.

Your best bet is to set the background-size using Javascript.
However, if you want the image to scale down if the container is smaller than it, you will have to be able to retrieve the image’s natural height.

if ($('.el').height() < imageHeight) {
  $('.el').css('background-size', 'contain');
}
else {
  $('.el').css('background-size', 'auto');
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)