Background Image Stretch On Homepage - html

I'm currently trying to make my background image on my homepage to stretch across the whole page, but I'm having difficulties doing this because when I try and re-size the window it becomes smaller?
this is my code:
<style type="text/css">
body{
background: url(img/phantom410.jpg); repeat-y;
background-size:cover;
background-color:black;
}
</style>
Is there a way I can get an image for my website homepage and stretch it across the whole page like what twitter does with their background image; but not have it shrink once it starts getting smaller? thanks!

body {
background: url(https://css-tricks.com/examples/FullPageBackgroundImage/images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
h1{
color:#FFF;
}
<html>
<head>
<title>Full Background</title>
</head>
<body>
<center><h1>Full Background Image</h1></center>
</body>
</html>

Related

fixing the background image for a game I'm making using HTML

It's me again with another new project for finals.
I'm trying to make a game with HTML and I'm in the middle of making the main menu right now and I'm stuck on it.
The background image wouldn't fit in right and I've searched and tried every solution I can find in the internet but it just wouldn't come out right.
Here's what it looks like. As you can see, it doesn't fit in right. I was trying to make the bg image fit in without having to scroll. I used a 1920x1080 image
body {
background-image: url("main menu bg.png");
background-size: contain;
background-repeat: no-repeat;
background-size: 100% 100%;
background-position: center top;
}
<!DOCTYPE html>
<html>
<head>
<link rel = "stylesheet"
type = "text/css"
href = "stylemenu.css" />
<title> Trio of Battles </title>
</head>
<body>
<button button style="background-color: transparent;" onclick="myFunction()"><img src="start button.png"></button>
</body>
</html>
By changing body height to 100vh, you make sure that there's no scrollbar. And with contain, the image will always fit inside the screen.
body {
background: url("main menu bg.png")no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: contain;
overflow: auto;
margin: 0;
height: 100vh;
}

why can't I stretch the image to the full screen of the page?

I make a site and decided to make the background,wrote the code and viewing the page of the site realized that the image is not on the whole page
what do I need to fix to make the image stretch to the whole page?
<html>
<head>
<title>text</title>
<style>
body{
background: url(back.jpg) no-repeat;
-moz-background-size: 100%
-webkit-background-size: 100%
-o-background-size: 100%
background-size: 100%
}
</style>
</head>
<body style="background-attachment:fixed" topmargin="0">
</body>
</html>
enter image description here
Try using background-size: cover; instead of 100%.
It resizes the background image to cover the entire container, even if it has to stretch the image or cut a little bit off one of the edges

Image declared in css is not showing

I want a image to fill the browsers and these are html side code
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
</body>
</html>
since I want the image to be occupied fully in screen i declared it inside the body in css like this but sadly image is not appearing in the screen
body{
background-image:url('../img/bgmapsimage.png');
background-repeat:no-repeat;
background-size:contain;
background-position:center;
}
yes the image name is correct and location is correct as well.This is the link i refered link
Check out this link: https://css-tricks.com/perfect-full-page-background-image/
body{
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;
}
You can also use vh to have full height image no matter the screen size.
To test your CSS, try to change the URL in this line
background-image:url('../img/bgmapsimage.png');
to an absolute URL of which you know it will work, like
background-image:url('http://placehold.it/400x300');
If this image is shown, your original image path is the problem (the folder structure which your HTML, CSS and image files are in). If it's not shown, most likely your CSS code itself is the reason.
Your body element is empty and therefore has no height.
if you add a minimum height, you'll see the image:
body{
background-image:url('../img/bgmapsimage.png');
background-repeat:no-repeat;
background-size:contain;
background-position:center;
min-height: 200px;
}
Update your CSS as like below
body{
background: url('../img/bgmapsimage.png') no-repeat center center fixed;
-webkit-background-size: center;
-moz-background-size: center;
-o-background-size: center;
background-size: center;
}
OR
body{
background: url('../img/bgmapsimage.png') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
You can also add css for html tag
Example
html{
/*Your CSS*/
}
Here is some CSS tricks for full screen background image CSS Tricks
body{
//backround image and all
background-size: cover;
}
Though it depends on the size of the image you are working with.

How to center a bigger background

I've done plenty of research on this but I must be doing something wrong because it never works for me. What I want to do is center the Vignette.png to overlay my other background, which is a repeating pattern. Unfortunately I can't still post images because of my still very low reputation :-). But basically what I want is the vignette, which is an image with 4k resolution, to center itself on the page, an if you have a bigger screen, you will see the surplus. But what seems to happen is that the image starts rendering at the top left corner and i can't even see the center of the image, because my screen isn't big enough. Again, I wish i could put some images to clarify my problem, but hopefully i've explained it well.
This is my code:
/* CSS */
body {
background-image: url("Vignette.png"), url("Pattern.png");
background-repeat: no-repeat, repeat;
background-position: center, auto;
}
<!-- HTML -->
<!DOCTYPE html>
<html>
<head>
<title>WIP</title>
<meta charset="UFT-8">
<link rel="stylesheet" href="style.css">
</head>
</html>
Thanks for answering!
I don't fully understand yet what exactly you want to achieve. But chances are that you get it trying with background-size: cover or background-size: contain.
Here is an example of centered image that expands until its actual size is reached, and then the margins/background appear, so it never goes bigger than its resolution:
#page {
background-image: url('some-image.jpg');
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
More info: http://www.w3schools.com/cssref/css3_pr_background-size.asp
I hope it helps
You need to add background-attachment: fixed to your CSS, and provide one generic rule for the position:
body {
background-image: url("http://lorempixel.com/400/200/"), url("http://lorempixel.com/40/40/");
background-repeat: no-repeat, repeat;
background-attachment: fixed;
background-position: center center;
}
<!DOCTYPE html>
<html>
<head>
<title>WIP</title>
<meta charset="UFT-8">
<link rel="stylesheet" href="style.css">
</head>
<body></body>
</html>
In response to your comment:
The background-attachment: fixed property allows the image to maintain it's position on the page regardless of the other elements, rather than inheriting it's position and thus flowing with the page.
The 'generic rule' I referred to simple replaces your rule which was in fact invalid CSS with a valid rule, which specifies the position of the background image to be centred both horizontally and vertically (in that order): background-position: center center.
Use background-size: cover; for this. I included an example, is this what you were trying to reach?
Here is some information about the backround-size attribute.
http://devdocs.io/css/background-size
/* CSS */
body {
background-image: url("http://www.handleidinghtml.nl/html/afbeeldingen/voorbeelden/usa3.gif"), url("Pattern.png");
background-repeat: no-repeat repeat;
background-position: center center;
background-size: cover;
}
<!-- HTML -->
<!DOCTYPE html>
<html>
<head>
<title>WIP</title>
<meta charset="UFT-8">
<link rel="stylesheet" href="style.css">
</head>
</html>

How to make full screen background in a web page

How to make an image as background for web page, regardless of the screen size displaying this web page? I want to display it properly. How?
its very simple
use this css (replace image.jpg with your background image)
body{height:100%;
width:100%;
background-image:url(image.jpg);/*your background image*/
background-repeat:no-repeat;/*we want to have one single image not a repeated one*/
background-size:cover;/*this sets the image to fullscreen covering the whole screen*/
/*css hack for ie*/
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.image.jpg',sizingMethod='scale');
-ms-filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.jpg',sizingMethod='scale')";
}
um why not just set an image to the bottom layer and forgo all the annoyances
<img src='yourmom.png' style='position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:-1;'>
Via jQuery plugins ;)
http://srobbin.com/jquery-plugins/backstretch/
http://buildinternet.com/project/supersized/
Use this CSS to make full screen backgound in a web page.
body {
margin:0;
padding:0;
background:url("https://static.vecteezy.com/system/resources/previews/000/106/719/original/vector-abstract-blue-wave-background.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Use the following code in your CSS
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;
}
here's the link where i found it:
Make a div 100% wide and 100% high. Then set a background image.
A quick search for keywords background generator shows this CSS3 produced background pattern that's dynamically created.
By keeping the image small and repeatable, you won't have problems with it loading on mobile devices and the small image file-size takes care of memory concerns.
Here's the markup for the head section:
<style type="text/css">
body {
background-image:url('path/to/your/image/background.png');
width: 100%;
height: 100%;
}
</style>
If your going to use an image of something that should preserve aspect ratio, such as people or objects, then you don't want 100% for width and height since that will stretch the image out of proportion. Instead check out this quick tutorial that shows different methods for applying background images using CSS.
CSS
.bbg {
/* The image used */
background-image: url('...');
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
HTML
<!doctype html>
<html class="h-100">
.
.
.
<body class="bbg">
</body>
.
.
.
</html>
I have followed this tutorial: https://css-tricks.com/perfect-full-page-background-image/
Specifically, the first Demo was the one that helped me out a lot!
CSS
{
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
this might help!
I found the reason why there is always a white boder of the background image, if I put the image in a 'div' element inside 'body'.
But the image can be full screen, if I put it as background image of 'body'.
Because the default 'margin' of 'body' is not zero.
After add this css, the background image can be full screen even I put it in 'div'.
body {
margin: 0px;
}