I'm trying to create a page where the background image is responsive to your browser's screen size. However, I need content under that image such that if the person scrolls down, the background image ends.
It's hard to explain so I've tried to create an image to make it clearer:
When you work with background images, you may want an image to stretch to fit the page despite the wide range of devices and screen sizes. The best way to stretch an image to fit the background of an element is to use the CSS3 property, for background-size, and set it equal to cover.
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
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.
Try this Fiddle:
HTML:
<div class='image'></div>
<div class='content'>Content</div>
Use absolute positioning to make the background image the same size as the screen, and put the content after, with a top
of 100%
:
body {
margin:0;
}
.image {
position:absolute;
width:100%;
height:100%;
background:green;
background-image:url('some-image.jpg');
background-size:cover;
}
.content {
position:absolute;
width:100%;
top:100%;
height: 100px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With