Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make the background image in DIV responsive

I want my background image to become responsive inside a div. It has a parallax effect when scrolled. I already tried to customize the background in the media queries but no hope it only adjust the height and doesn't contain the whole page when in mobile devices width. Can someone give me a clue to solve this? Im new to html and css.

html code for div:

<div class="parallax"></div>

css code:

.parallax { 
    height: 502px;
    background-image: url(../img/back2.png);
    background-attachment: fixed;
    background-position: -70px 80px;
    background-repeat: no-repeat;
    background-size: cover;
}

@media screen and (min-width: 270px) and (max-width: 320px){ 
.parallax { 
    max-height: 300px;
    background-image: url(../img/back2.png);
    background-attachment: fixed;
    background-position: -70px 40px;
    background-repeat: no-repeat;
    background-size: cover;
}
}
like image 236
hihihihi Avatar asked Jul 05 '26 23:07

hihihihi


1 Answers

You should use property: background-size:100% auto;

If the width property is set to 100%, the image will be responsive and scale up and down.

please see this link for more info: w3schools

like image 122
Farhad Avatar answered Jul 07 '26 14:07

Farhad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!