BoomyBiscuit 45
BoomyBiscuit 45

Reputation: 54

Background image doesn't show on small devices CSS

Background image doesn't show on small devices CSS. I have a background image that gets zoomed in via CSS but when the screen is made smaller the background image disappears and is white. I am trying to make an app so it needs to work on all devices and sizes. This does work fine when it doesn't zoom in. I have pasted my code below. Thanks

* {-webkit-tap-highlight-color: rgba(0, 0, 0, 0):}

body {
-webkit-touch-callout: none;
/* prevent callout to copy image, etc when tap to hold */
-webkit-text-size-adjust: none;
/* prevent webkit from resizing text to fit */
-webkit-user-select: none;
/* prevent copy paste, to allow, change 'none' to 'text' */
background-color: #E4E4E4;
);
background-attachment: fixed;
}

/* Portrait layout (default) */

.app {
position: absolute;
/* position in the center of the screen */
background-position: center;
position: relative;
bottom: -300px;
font-family: 'Roboto', sans-serif;
}

/* Landscape layout (with min-width) */

@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {

h1 {
    font-size: 90px;
    font-weight: normal;
    margin: 0px;
    overflow: visible;
    padding: 0px;
    text-align: center;
    color: white;
    font-family: 'Roboto', sans-serif;
}
p {
    color: blue;
    font-family: 'Roboto', sans-serif;
    font-size: 15px;
    text-align: center;
    color: white;
}
.event {
    border-radius: 4px;
    -webkit-border-radius: 4px;
    color: #FFFFFF;
    font-size: 12px;
    margin: 0px 30px;
    padding: 2px 0px;
}
.createAnAccount {
    padding-bottom: 10px;
    padding-top: 10px;
    font-size: 15px;
}
.logintable {
    text-align: center;
}
.login {
    padding-bottom: 10px;
    padding-top: 10px;
    font-size: 15px;
}
.event.listening {
    background-color: #333333;
    display: block;
}
.event.received {
    background-color: #4B946A;
    display: none;
}
@keyframes fade {
    from {
        opacity: 1.0;
    }
    50% {
        opacity: 0.4;
    }
    to {
        opacity: 1.0;
    }
}
@-webkit-keyframes fade {
    from {
        opacity: 1.0;
    }
    50% {
        opacity: 0.4;
    }
    to {
        opacity: 1.0;
    }
}
.blink {
    animation: fade 3000ms infinite;
    -webkit-animation: fade 3000ms infinite;
}
.bg {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -999;
}
.background {
    background: #22313F;
    background-image: url(https://i.ytimg.com/vi/b7WD-
    SpNX_I/maxresdefault.jpg);
    background-size: cover;
    width: 100%;
    height: 100%;
    animation: zoom 12s forwards ease-out;

Html code below

<body>
    <div class="bg">
        <div class="background"></div>
    </div>
<body>

Upvotes: 0

Views: 821

Answers (1)

Your @media query has minimun pixel limit. If you delete this, it will work. So change this line

@media screen and (min-aspect-ratio: 1/1) and (min-width:400px)

into this

@media screen and (min-aspect-ratio: 1/1)

By setting min-width you only apply this background changes if the viewport is 400 pixels wide or wider.

Upvotes: 2

Related Questions