Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed background cover becomes zoomed in mobile view

I'm using a fixed background cover for my website here: http://www.datisdesign.com

Every page has a big header image, but in small devices such as mobiles, the cover image becomes so large. I want to make it smaller in mobile devices.

This the code that I'm using:

#takelessons {
    background: url(../img/portfolio/takelessons-intro.jpg) no-repeat;
    background-attachment: fixed;
    background-size: cover;
    background-position: center top;
}

Normal view

Mobile view

like image 827
datisdesign Avatar asked May 23 '14 21:05

datisdesign


People also ask

Does fixed background work on mobile?

background-attachment: fixed in CSS, at best, does not work well in mobile browsers, and at worst is not even supported by the most widely used mobile browsers. You can ditch this idea completely and let the background scroll on small screens using media queries.

How can I make my background image resize to fit any screen?

Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.

How do you keep the background of a picture fixed?

To keep your background fixed, scroll, or local in CSS, we have to use the background-attachment property. Background-attachment: This property is used in CSS to set a background image as fixed or scroll. The default value of this property is scroll.


1 Answers

I solved my problem by limiting the capability to the large tablet screen size.

@media screen and (max-width: 992px) {
    #parallax {
        background-attachment: scroll;
    }
}
like image 85
R.Cha Avatar answered Oct 29 '22 21:10

R.Cha