Alex Zakruzhetskyi
Alex Zakruzhetskyi

Reputation: 1433

How can I make a background image scalebale

I have a banner div:

<div class="background" style="background: url(<%= @banner.image.url(:big) %>) no-repeat"></div>

and corresponding css:

#banner {
  width: 100%;
  height: 275px;
}

#banner .background {
  width: 100%;
  height: 275px;
  background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  -webkit-background-size: cover;
}

uploader.rb:

version :big do
  process resize_to_fill: [1920, 280]
end

On smaller devices, the background-image is cropped, here are the screenshots. Full width:

enter image description here

And a resized window:

enter image description here

Is there any way to make the image be resizable when the screen width becomes narrow? Thanks.

Upvotes: 0

Views: 35

Answers (2)

Super User
Super User

Reputation: 9642

Just use background-size: contain for this

#banner .background {
    background-size: contain; 
}

Upvotes: 4

Ismail Farooq
Ismail Farooq

Reputation: 6837

try background-size: 100% auto;

Upvotes: 2

Related Questions