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
Related
In my css file, I have an id named "homehero", which displays a background image.
#homehero
{
background-image: url("images/coast.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
}
In my html file, I have a div that uses this id to display the image; however, the image does not appear whatsoever.
<div id="homehero"> <!-- Home Page Image -->
<!-- <img src="images/coast.jpg" width="100%" height="100%" alt="A Sunny Coastline"> -->
<!-- Old line of html that displayed the same image, but converted to css id. -->
</div> <!-- End of Home Page Image -->
The full html file can be found here.
The full css file can be found here.
Edit:
The image is displayed when setting it as the background image for another element, it is only in this id where the issue occurs.
Please Put width and height
width:100%;
height:100vh;
#homehero
{
background-image: url("images/coast.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
width:100%;
height:100vh;
}
I would suggest below changes,
#homehero
{
background-image: url("images/coast.jpg");
width:300px;
height:300px;
background-size: cover;
background-repeat: no-repeat;
}
Where, your image will be cover and if you specifies width and height it would be good and also your image will not be repeat as no-repeat property is used.
These are a few things I recommend you try:
Try setting the background size. (Instead of %, try setting it to px.)
Most of the time, the background picture is applied, but because our div has
no dimension, we are unable to view it.
Double-check that your picture file is located in the images folder.
Check your image's extension and make sure you're using the correct one in your code.
Use the dev tools to inspect the element and see whether the background property is being overridden by another CSS rule.
If none of the above methods work, try pasting the picture's real URL by copying the image address from the internet rather than providing a folder path.
This method works 90% of the time.
i recommend to use inline scope css, i hope it works for you
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="#homehero {.css">
<style>
#homehero {
background-image: url("image/image.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div>
<div id="homehero">
</div>
</div>
</body>
</html>
this might be the reason why it can happen
https://www.geeksforgeeks.org/types-of-css-cascading-style-sheet/#:~:text=As%20Inline%20has%20the%20highest,sheets%20have%20the%20least%20priority.
It looks like you're entering the url in the background image, for background size using background-size: cover;
If your url address is correct, then try adding
width:100%;
height:100vh;
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'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>
My code is below. The Hyperlink is there so that if you click on the picture it takes you to a different page but that page is not apart of my question. What i'm trying to do is use css to re-size an image according to the height of your web browser. In google chrome it works, but not in ie and idk about firefox. If someone could tell me what was wrong and rewrite my code in a way that would make it work for all browsers it would be much appreciated.
<!DOCTYPE html>
<head>
<style>
.size{height:100%;}
.test{width:auto;height:100%;}
</style>
</head>
<body>
<div class="size">
<img class="test" src="test.jpg" border="0">
</div>
</body>
You can put the image in a container and then set the css as follows
<html>
<head>
<style>
a.container {
width:100%;
height:100%;
display:block;
}
a#image1 {
background: url(YOURIMAGE.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
</head>
<body>
<a class="container" id="image1" href="#"></a>
</body>
</html>
Then you can ID each a tag that you want to have as a link and create a reference in css for it. This will not make the entire image fill the page and also be a link.
I'm having problems adding a background image to my background website in the html tag.
The problem is here:
html{
background:url('assets/img/jp-logo.png'); /*background image*/
background-image:url('assets/img/jp-logo.png'); /*background image*/
-webkit-background-size: cover;
-moz-background-size: cover;
}
I put in both background and background image because i testing whether either one would work along with the background size: cover but none of them did. I also checked my file directory paths, those are good too. I was wondering why as that's not supposed to happen. i tested it on a seaprate html and css test sheet and it worked, but why not here is suspicious to me. The full code here: http://jsfiddle.net/TheAmazingKnight/kjLg8/
This short sample I made worked:
<!doctype html>
<html lang="en">
<head>
<title>Test Page</title>
<link rel="stylesheet" href="test.css" type="text/css" media="screen" /> <!--CSS for desktop screens-->
</head>
<body>
<p>hello</p>
<img src="jp-logo.png" alt="jp-logo.png" />
</body>
</html>
html{
background-image:url('assets/img/jp-logo.png');
}
html has no semantic value. Use body instead. You may want to give your body a margin:0;.
I changed your background photo and placed into body element like this:
body{
background:url(http://technomarketer.typepad.com/technomarketer//Radiohead_wallpaper.jpg); /*background image*/
-webkit-background-size: cover;
-moz-background-size: cover;
and it worked.
So, maybe your path to the photo (assets/img/jp-logo.png) is wrong.
Did you check it?
html{
background:url("assets/img/jp-logo.png") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
I found that this code works perfect and to give credit where credit is due:
http://css-tricks.com/perfect-full-page-background-image/
if you want to write css code inside html page be like this
<head>
<title>hello</title>
<style type="text/css">
html{
background: url(photo.jpg);
}
</style>
</head>
and the image url not between quotation mark 'image.jpg'
and it`s better to use body instead of html