I have a background image covering the entire width and height of the browser screen. It works in chrome and IE but in Firefox the image is being pushed down. Any ideas what's happening?
/* CSS */
<style type="text/css">
#bg {
position:fixed;
top:0;
left:-50%;
width:200%;
height:75%;
}
#bg img {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
margin:auto;
min-width:50%;
min-height:50%;
}
</style>
/* HTML */
<div id="bg">
<img src="http://image.iloqal.com/lib/fe5c1570746107757c1c/m/1/BMW_528_bkg.png" id="back1" alt="" />
</div>
You should try the following to make the image fullscreen:
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
For details, have a look here.
Justin first of all, by definition a BACKGROUND image, is set via CSS and not inline as you do it. So, a first solution is rather simple:
#bg {background: url("images/yourimage.jpg") no-repeat center fixed;}
It will put your background in the center, and there you go. the #bg acts as a wrapper for the rest of your content/markup.
Now if you want your background to automatically resize depending on the browser window, there is no way to do it if you can't use CSS3.
ps: note that you can fake a background taking the whole screen by photoshoping a very long and wide image that will repeat a background color, and by using the background shorthand like that:
#example { background: #fff url(image.gif) no-repeat; }
So if your car image is covered by a white background color, it will be ok not only for the original image resolutions, but also for bigger ones as the white color will cover the browser window.
Please comment if you have more specific needs.
If you can't use CSS3 - change following code
#bg img {
position:absolute;
top:-50%;
left:0;
right:0;
bottom:0;
margin:0 auto;
min-width:50%;
min-height:50%;
}
Related
i am working on a bootstrap-based website and i have placed a big image on top of it.
<div class="container-fluid introimage">
<img src="img/wald.gif">
</div>
Now i want the container to be only as high as the browser-window is and i like to have the image to be aligned on bottom of the container, to get sure, that the bottom of the image is always visible.
I've tried something, but it did not work at all:
.introimage {height: 100%;}
.introimage img {vertical-align: bottom;}
Could you please help me? Thanks in advance!
This is the website: http://baustelle.injuvik.de
Put the image in the background of the container.
Simply apply these styles to your website, and it should work
body, html {
height:100%;
}
.introimage {
height: 100%;
background-image: url(img/wald.gif);
background-size: cover;
background-position: bottom;
}
use min-height:100% with height:100% on body
.introimage {
height: 100%;
min-height: 100%;
}
html, body {
height: 100%;
min-height: 100%;
}
Use the unit vh . It represent viewport height, and go from 0 to 100.
.introimage{
height:100vh;
}
Add following rules in your style sheet, What I have done is set the container to position fixed; so that it works w.r.t screen and made its height, width 100% so that it covers complete screen, then I aligned the element from top left corner and in the last set the image to cover complete parent div thus indirectly covering compelte browser window.
.introimage {
height: 100%;
position:fixed;
top:0;
left:0;
width:100%
}
.introimage img {
height:100%;
width:100%
}
I would recommend using the newer vh measurement for your stage, which will make any element the height of the veiwport with a value of 100.
.introimage {
position: relative;
height: 100vh;
background-color:transparent;
}
I would then use that image as a background image as opposed to just an image tag. I'd probably add it to the after pseudo-element of .introimage.
.introimage:after {
content:'';
display:block;
position: absolute;
top:0;
right:0;
bottom:0;
left:0;
background: url(images/bg.jpg) no-repeat center bottom fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
https://css-tricks.com/perfect-full-page-background-image/
I'm trying to make a GIF fit my whole screen, but so far its just a small square that is on my screen while the rest is white. However, I want it to take up all the space.
Any ideas?
if it's background, use background-size: cover;
body{
background-image: url('http://i.stack.imgur.com/kx8MT.gif');
background-size: cover;
height: 100vh;
padding:0;
margin:0;
}
IMG Method
If you want the image to be a stand alone element, use this CSS:
#selector {
width:100%;
height:100%;
}
With this HTML:
<img src='folder/image.gif' id='selector'/>
Fiddle
Please note that the img tag would have to be inside the body tag ONLY. If it were inside anything else, it may not fill the entire screen based on the other elements properties. This method will also not work if the page is taller than the image. It will leave white space. This is where the background method comes in
Background Image Method
If you want it to be the background image of you page, you can use this CSS:
body {
background-image:url('folder/image.gif');
background-size:100%;
background-repeat: repeat-y;
background-attachment: fixed;
height:100%;
width:100%;
}
Fiddle
Or the shorthand version:
body {
background:url('folder/image.gif') repeat-y 100% 100% fixed;
height:100%;
width:100%;
}
Fiddle
You can set up a background with your GIF file and set the body this way:
body{
background-image:url('http://www.example.com/yourfile.gif');
background-position: center;
background-size: cover;
}
Change background image URL with your GIF. With background-position: center you can put the image to the center and with background-size: cover you set the picture to fit all the screen. You can also set background-size: contain if you want to fit the picture at 100% of the screen but without leaving any part of the picture without showing.
Here's more info about the property:
http://www.w3schools.com/cssref/css3_pr_background-size.asp
Hope it helps :)
if you're happy using it as a background image and CSS3 then background-size: cover; would do the trick
This should do what you're looking for.
CSS:
html, body {
height: 100%;
margin: 0;
}
.gif-container {
background: url("image.gif") center;
background-size: cover;
height: 100%;
}
HTML:
<div class="gif-container"></div>
In your CSS Style tag put this:
body {
background: url('yourgif.gif') no-repeat center center fixed;
background-size: cover;
}
Also make sure that it's parent size is 100%
based on a recommendation ("css only technique number 1" here http://css-tricks.com/perfect-full-page-background-image/), i used an inline img element and css to make a background image that would fill the whole browser window.
it all works fine except that under a certain width of window, when the image resizes it starts compressing the image horizontally, in other words, not maintaining the aspect ratio of the image.
for instance, this jfiddle...if you move the browser around you can see honey boo boo's aspect ratio is not preserved.
http://jsfiddle.net/4040newb/h7QMv/2/
<div class="container-fluid">
<a href="gallery.html">
<img src="http://thenypost.files.wordpress.com/2013/09/tv-honey_boo_boo.jpg" class="bg "/>
</a>
</div><!-- .container -->
I would highly recommend using the CSS3 method described first in the post - It's a simpler and more reliable method:
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Instead of using img element, you can just apply the background image to the div (or any other container stretched accordingly to the browser borders).
Then, you do the following for the background:
.picture {
background-image: url(...);
background-size:cover; /* this way */
background-size:content; /* or this one (which you prefer) */
}
... to stretch the image accordingly to its container size.
EDIT:
Also, in this very case:
html, body
{
width:100%;
height:100%;
margin:0;
padding:0;
}
.container-fluid
{
min-width:100%;
min-height:100%;
background-position:center;
}
(But this is an example -- you should play with your layouts by your own then).
Im trying to add a background photo to a part of a website using css. I'd like to set the photo as "cover" to stretch and resize it as the browser from a visitor lets it to.
The thing is, i'd like to split the website in 2 parts, #top and #bottom. Whereas the top half is about 79% and bottom 21%.The #top part will contain the "cover" photo, whereas the bottom half will have a certain background color.
My problem is, that my current setup "sort of" works for IE (stretching is a bit off), but does not for Firefox and Chrome. I've tried many different things, but just can't get it right.
The problem that occurs is, that in Firefox and Chrome the "cover" photo clips behind the bottom background, whereas in IE, the photo actually works as intended, and fills the #top part.
<html>
<head>
<title>Test</title>
<style>
html {
width:100%;
height:100%;
color:white;
}
body {
height:100%;
width:100%;
}
#top {
background: url(PZwx1) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/BV-site-bgfoto.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/BV-site-bgfoto.jpg', sizingMethod='scale')";
height:79%;
}
#bottom {background: #F9525F;height:21%;}enter code here
</style>
</head>
<body>
<div id="top"></div>
<div id="bottom"></div>
</body>
</html>
I've worked out the example here to; http://www.webdevout.net/test?02X
Any help is much appreciated!
Remove the "background:fixed" (it's what make it use 100% of the page height) and use "100% 100%" instead of "cover". That should do it.
#top {
background: url(lalala.jpg) no-repeat center center;
background-size:100% 100%;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='lalala.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='lalala.jpg', sizingMethod='scale')";
height:79%;
}
If the fixed is important, then use background-size:100% 79% and change the background:center to background:top
#top {
background: url(lalala.jpg) no-repeat top fixed;
background-size:100% 79%;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='lalala.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='lalala.jpg', sizingMethod='scale')";
height:79%;
}
(also, add padding:0,margin:0 to your body)
I have a full screen background image, which keeps the aspect ratio and works in all browsers fine but not in Safari. I'm good at CSS but at this point I don't know exactly what the problem is. It seems that Safari has a problem keeping the vertical center and creates gaps at the top and bottom:
<div id="bg">
<div style="display: table-cell">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="loading"><img src="images/home.jpg" /></td>
</tr>
</table>
</div>
</div>
CSS:
html,body,#bg,#bg table,#bg td {
width:100%;
height:100%;
overflow:hidden;
position: relative
}
#bg div{
position:absolute;
width:200%;
height:200%;
top:-50%;
left:-50%
}
#bg td{
vertical-align:middle;
text-align:center
}
#bg img{
min-height:50%;
min-width:50%;
margin:0 auto;
display: table
}
Any CSS crhacks here?
If you are looking to use an actual image as a background instead of a background image in your CSS, a JavaScript solution might be better suited for your needs as it doesn't introduce extraneous markup into your design.
Check out jQueryMaxImage: http://www.aaronvanderzwan.com/maximage/ and here's one that I wrote, jquery.FullScreenBG: https://github.com/huntedsnark/jquery.fullScreenBG
If you don't want to do it with a script there is a way to do it using CSS# plus non-standard CSS for compatability:
html {
background: url(images/yourImage.jpg) no-repeat center center fixed;
/* CSS3 */
background-size: cover;
/*other browser specific */
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
/* non-standard for IE */
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.yourImage.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='yourImage.jpg', sizingMethod='scale')"
}
You really should not be adding all kinds of table markup for the sake of a background image.