I am using a page with HTML body and some property associated with body defined in the head section. while Executing the page image is rendering sometime and sometime not.
<head>
<style type="text/css">
body {
background-image: url('Assets/Img/bg2.jpg');
background-size: cover; /* <------ */
background-repeat: no-repeat;
background-position: center center; /* optional, center the image */
}
</style>
</head>
body section
<body class="signup-page">
<div id="content"></div>
</body>
What is the issue Exactly? Any idea would be appreciated.
Related
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;
}
I have a problem in bootstrap/css. I want to load image from source folder and I typed in css this code:
background: url('../img/home.jpg') no-repeat;
But it doesn't show in my home section on the page.
https://codepen.io/write/image-not-loading
Perhaps try
background-size: cover;
Or as ZohirSalak CeNa said, resizing your element that is containing the background image unless it is your body.
HTML
<html>
<head>
<title>Your Title</title>
</head>
<body class="your-class">
</body>
</html
CSS
.your-class {
background-image: url('../img/home.jpg') no-repeat;
background-size: cover;
}
Also, Make sure you have the correct path to your image
I am currently haven issues displaying the background img of my site. the problem is probably in my css but caused by the layout of my html.
In order to show a navbar on each page without duplicated code, i simply let my controller parse a navbar file and a content file.
the navbar.html has a layout of
<html>
<body>
//navbar code
</body>
</html>
while the content file have a layout of
<html>
<head>
//head code
</head>
<body>
//body code
</body>
</html>
i parse this from the controller using
$this->parser->parse('navbar', $data);
$this->parser->parse('content', $data);
which leads to a final source code of
<html>
<body>
//navbar code
</body>
</html>
<html>
<head>
//head code
</head>
<body>
//body code
</body>
</html>
Now i got the image responsive on all pages without header with this css
html, body{
//make body fill entire page
width: 100%;
//height: 100%;
margin: 0;
background:
/* top, transparent black, faked with gradient */
linear-gradient(
rgba(0, 0, 0, 0.4),
rgba(0, 0, 0, 0.4)
),
/* bottom, image */
url("http://webapps.groept.be/a15_web01/img/wallpaper.jpg");
/*make sure background image is responsive*/
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
The pages where i load both the navbar and content now put the body at height:100% which ofcourse means that the content overlaps the navbar.
Is there a way to adjust the css for this? or does anyone know a better layout for the navbar issue?
Ok i found it, i'll quickly list the useful answers as an overview.
Removed <html> and body tags from navbar file
changed css to only work on the html tag
added css: body{ background-color: transparent; }
anyway, thanks for the help guys
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>
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>