-1

I am trying to change a background image size from "cover" to "contain" based on the screen size.

I currently have:

style="background-image: url('images/hbc/slider-3.webp'); background-size: cover;"

I want to change it to background-size: contain; for phones only.

I have tried everything I thought might make sense.

Md. Rakibul Islam
  • 2,140
  • 1
  • 7
  • 14
Bruce C
  • 3
  • 1

1 Answers1

2

If you have now

.block-img{
    background-image: url('images/hbc/slider-3.webp'); 
    background-size: cover;
}

you need

@media(max-width:768px){
    .block-img{
        background-size:contain;
    }
}

When the screen becomes less than 768 pixels (for phones), this block will change its property cover to contain.

ahuemmer
  • 1,653
  • 9
  • 22
  • 29