Full-screen responsive background image
http://css-tricks.com/perfect-full-page-background-image/
//HTML
<img src="images/bg.jpg" id="bg" alt="Sample Image">
//CSS
#bg {
position: fixed;
top: 0;
left: 0;
/* Preserve aspet ratio */
min-width: 100%;
min-height: 100%;
}
OR
img.bg {
/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
}
@media screen and (max-width: 1024px) { /* Specific to this particular image */
img.bg {
left: 50%;
margin-left: -512px; /* 50% */
}
}
OR
//HTML
<img src="images/bg.jpg" id="bg" alt="Sample Image">
//CSS
#bg { position: fixed; top: 0; left: 0; }
.bgwidth { width: 100%; }
.bgheight { height: 100%; }
//jQuery
$(window).load(function() {
var theWindow = $(window),
$bg = $("#bg"),
aspectRatio = $bg.width() / $bg.height();
function resizeBg() {
if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
$bg
.removeClass()
.addClass('bgheight');
} else {
$bg
.removeClass()
.addClass('bgwidth');
}
}
theWindow.resize(resizeBg).trigger("resize");
});
Fullscreen responsive background image in CSS
jsBin demo
background: url(image.jpg) fixed 50%;
background-size: cover; /* PS: Use separately here cause of Safari bug */
The fixed
(background-attachment) is optional.
The above is just a shorthand for:
background-image : url(image.jpg);
background-attachment : fixed;
background-position : 50% 50%; /* or: center center */
background-size : cover; /* CSS3 */
You've could in all modern browsers but Safari use:
background: url(image.jpg) fixed 50% / cover;
where the /
is used in background shorthand to separate and distinguish position
from size
(cause position accepts both single and multiple (X,Y) values), but Safari has a bug with this /
shorthand so use as described above.
Responsive Background Image - Fullscreen
Did you tried this :
body {
margin:0;
padding:0;
background: url('/images/bg.jpeg') no-repeat center fixed;
-webkit-background-size: cover;
background-size: cover;
}
Full screen responsive background - then normal
From what I understand you are looking for something like this:
body { background-image: url(http://www.gettyimages.co.uk/gi-resources/images/CreativeImages/Hero-527920799.jpg); background-position: center center; background-repeat: no-repeat; background-attachment: fixed; background-size: cover; margin:0}.content { position: absolute; bottom: -100px; width: 100%; background: #FF6969; height: 100px;}.moreContent { position: absolute; height: 100px; bottom: -200px; width: 100%; background: white;}
<body> <div class="content"> Hello this is my content <br/> <br/> <br/> <br/>Lots of content </div>
<div class="moreContent"> more content... </div>
</body>
full screen responsive background image with bootstrap
Two options
use
img-responsive
class if you are using tag.<div class="wrapper">
<img src="pic_1.jpg" class="img-responsive" alt="Responsive image">
</div>if you are using css use this.
.wrapper{background: url('/assets/64531/green_suburb.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;}
How to maintain responsive background image height while changing screen width?
You need to get the html element (or whatever element you want the img to show in) to have at least the full height of the img when the img has full width (100vw) of the viewport.
You can do that if you know the aspect ratio of the image. In this case you know the natural width and height of the original so the aspect ratio can be calculated by CSS if you give it those dimensions as variables.
Here's an example using your CSS settings (except see caveat below):
* {
margin: 0;
padding: 0;
}
html {
--imgw: 1391;
--imgh: 2471;
width: 100vw;
min-height: calc(100vw * var(--imgh) / var(--imgw));
/* make sure the whole height of the image is always shown */
background-image: url(https://picsum.photos/id/1015/1391/2471);
background-size: cover;
}
HELLO
Related Topics
How to Reference One CSS Rule Within Another
Css Media Query to Target Only iOS Devices
Css 3 Shape: "Inverse Circle" or "Cut Out Circle"
How to Scale CSS Sprites When Used as Background-Image
Using CSS Transitions in CSS Grid Layout
Prevent That a Fixed Element Resizes When Zooming on Touchscreen
Scrollable Menu with Bootstrap - Menu Expanding Its Container When It Should Not
Using CSS, Can You Apply a Gradient Mask to Fade to the Background Over Text
How Can One Import Only Variables and Mixins from SASS Stylesheets
CSS Transition with Visibility Not Working
Segments in a Circle Using CSS3
@Font-Face Src: Local - How to Use the Local Font If the User Already Has It
Bootstrap Dropdowns Menus Appearing Behind Other Elements - IE7
Css: Styled a Checkbox to Look Like a Button, Is There a Hover
What Is the Best CSS Framework and Are They Worth the Effort
How to Automatically Crop and Center an Image
How to Change the Height of an Image in CSS :Before/:After Pseudo-Elements