Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

responsive div background, but no repeat

I'm trying to make this div background to act as a normal 100% image and scale the same way.

My CSS:

.videobackground{
margin-top:-5px;
max-width:1140px;
height:348px !important;
background-image:url(imgs/rpp-behind-the-scenes-hero2bg.jpg);
background-position:center; /* IE fix */
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
}

My HTML:

<div class="videobackground"></div>

Here is my issue on desktop it's looking perfectly fine.

Desktop Picture:

enter image description here

But as soon as I start to scale the page this happens.

Mobile Picture:

enter image description here

Any suggestions will be greatly appreciated, I feel like I've tried just about everything. And the reason I'm using a div background as opposed to just an image, I'm overlaying a youtube embed over the left side of the div.

Thanks so much!

Adam.

like image 498
adambwhitten Avatar asked May 09 '26 00:05

adambwhitten


1 Answers

You could add

background-repeat: no-repeat;

To your css.

So it looks something like

.videobackground{
margin-top:-5px;
max-width:1140px;
height:348px !important;
background-image:url(imgs/rpp-behind-the-scenes-hero2bg.jpg);
background-position:center; /* IE fix */
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
background-repeat: no-repeat;
}

Also here's a great link on getting full container backgrounds. https://css-tricks.com/perfect-full-page-background-image/

Also as a side note you could use short hand and combine all your css properties.

  background: url(imgs/rpp-behind-the-scenes-hero2bg.jpg) no-repeat center center fixed; 
like image 135
Isabel Inc Avatar answered May 12 '26 00:05

Isabel Inc



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!