GIF image not displaying when added via CSS - html

I want to add a GIF image to my webpage via CSS, the size of the image should be 100px X 100px.
The file structure is as follows:
Folder:
/index.html
/car.gif
I have added the JSFiddle of the code. Can someone correct it? The GIF is not getting displayed on index.html:
Code
<html>
<head>
<style type="text/css">
#position {
background-image: url('car.gif');
width: 25px;
height: 25px;
position: absolute;
}
</style>
</head>
<body>
dd
<div id="position"></div>
ss
</body>
</html>

The image (car.gif) must reside in the same directory as the CSS if you do not specify an absolute path. For this reason, the JS fiddle is useless. Check to make sure that your files are in the places you suggested they are in.
You also might benefit from a more explicit background statement, such as:
background: url('car.gif') top left no-repeat transparent;
Moreover, if your image's native size is 100px by 100px, you will need to resize it to see it properly:
background-size: 25px 25px;
I updated the other fiddle to include a more relevant version for your question:
http://jsfiddle.net/qtxg2jz5/6/
To answer Astro's comment, I can't comment on posts because I don't have enough reputation yet.

I have tested your code in my browser by replacing an image from my desktop and Image was showing up.
Once just make a change to its width and height :
width: 25px;
height: 25px;
to
width: 100px;
height: 100px;
Also Once Check this...
Ex : If our Page Url is :
www.yoursite.com/css/index.php
make sure car.gif can be accessed if you replace index.php with car.gif,
www.yoursite.com/css/cars.gif
is accessible or not.
Thats nothing but means that that file should be in same folder..
try them and hope you will get results you need..

Make sure the file car.gif is exist at the same directory or use absolute url to the image
DEMO

Related

Turning a background image into a link with CSS

I know there are similar questions but they don't exactly answer my problem. Am trying something really simple, turning a background image into a link, am following a tutorial and he did it easily so i tried it but it just didn't work, the image just doesn't show, i did all my checks from the tutorial but it just doesn't work for me.
<!DOCTYPE html>
<html>
<head>
<title>CSS</title>
<meta charset="utf-8">
<link rel="stylesheet" href="s017.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto" rel="stylesheet">
</head>
<body>
<h1>CSS</h1>
</body>
</html>
body{
font-family: open-sans, sans-serif;
}
#fb/*, #tw, #sc, #in, #ig, #wa*/{
height: 60px;
width: 60px;
display: block;
position: absolute;
}
#fb {
background-image: url('image03.png');
background-position: 0px 0px;
}
as for the result:
as you can see there is nothing in there other than the title
i taught it was the browser but i tried it with Mozilla and Chrome with same result.
If you are trying to use this as thumbnails, I recommend just using images instead of trying to set background images. When you are setting the background image, it isn't resizing the image, but showing a small 60x60px section of the image in the background. If the top left corner is white, that's what you are seeing. Instead of background image, try this:
<a href="https://www.facebook.com">
<img id="fb" src="http://blog.addthiscdn.com/wp-content/uploads/2015/11/logo-facebook.png">
</a>
Here's a working codepen showing what I believe you are looking for. If this isn't exactly it, or there's a reason specifically you must use background image, let me know and i'll update my answer to reflect.
At first please be sure that your link for CSS file is working , As you know you should put your Style codes in s017.css file that is in your html file folder.
Probably your image size is big and didnt fit in your 60*60 (a) tag block or your image have a white space in left top position that you intered.For the first you can use background-size in css for " #fb " :
background-size:contain;
and for the 2nd probability you should crop your image with paint or other image editors.Of course,you can set the position in center of image but this is not recommended.
I hope this work for you!
Have fun !!

div Img background doesn't work in my CSS

So this is my CSS code:
#plaatje {
background-image: url('Plaatjes\slider_two_temp.jpg');
width: 100%;
height: 600px;
position: absolute;
top: 0px;
left: 0px;
}
And it won't work at all. I placed the picture in the same map as my HTML file.
your code looks fine do a couple of things!
First check whether the id #plaatje is referenced correctly? also check for the path of css and html file
second check the path for your image the path you give in css is relative to your css file you should enter the correct path! if you're not sure about that use absolute path e.g background-image: url('http://localhost/Plaatjes/images/slider_two_temp.jpg'); but beware if you have a large application you might then need to change all the paths for live server!
the last thing you could do is to hit ctrl+f12 for inspect element there you can what actually is wrong with your code!
also check your console by hitting ctrl+f12 many times the issues is that we are not using the correct path for our files which results in File not found error
if none of above works share your html code , css code so we can have a look at it
hope that helps!!!
What you can try is you can enclose your id details in a style tag and you can make id name to any tag like paragraph tag and after that all your code will be alright.
<style>
#plaatje{
background-image: url('Plaatjes/slider_two_temp.jpg');
width: 100%;
height: 600px;
position: absolute;
top: 0px;
left: 0px;
}
</style>
<p id="plaatje"></p>
If you want to try this by
<div id="plaatje"></div>
it will also work fine for div tag
try this i think
#plaatje {
background-image:url('http://investorplace.com/wp-content/uploads/2016/02/google-amazon-goog-amzn-stock-300x200.jpg');
}
https://jsfiddle.net/karanmehta786/rd1yezc2/

Background image in id selector not showing up

I cannot get this background image to appear. It is supposed to appear in the background with the header overlapping it. I'm using an id selector. I literally copied this straight from the book i have for my class and it's not working at all.
Here is my code. I'm very new to css
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fall Nature Hikes</title>
<style>
#content { background-image: url(fall.jpg);
background-repeat: no-repeat;
margin-left: auto;
margin-right: auto;
width: 640px;
height: 480px;
padding-top: 20px; }
h1 { background-color: #FFFFFF;
opacity: 0.6;
font-size: 4em;
padding: 10 px; }
</style>
</head>
<body>
<div id="content">
<h1>Fall Nature Hikes</h1>
</div>
</body>
</html>
In my browser it works right for another image, you can check the url(fall.jpg) path is right?
I checked, your code can show the image, you can see this sample:
> https://jsfiddle.net/a9qm1j2t/
It's just copy all your html and css source code.
I think you should check image path and image type again, and make sure it's right.
May be your image path is not proper.
First check where is your css file and image file.You can verify your image path by inspecting your code on browser and in style check your image path.

Background-image not appearing

I'm new to HTML and CSS in general. Please help me with the code. I cannot get the background-image to appear in my browser although i typed the syntax correctly. All i get is an orange box, with no alert.png image. I'm following an online tutorial btw: http://dev.opera.com/articles/view/31-css-background-images/#thecode
Edit 1: The image, html file and css file are all inside the same folder. Yet no success.
Edit 2: I used an unique css file name instead of a generic "style.css" (which i have several of them in my system) and it worked! Make sure there's no space between url and the parenthesis.
HTMl code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">
<title>alert message</title>
</head>
<body>
<p class="alert">
<strong>Alert!</strong>
This is an alert message.
</p>
</body>
</html>
CSS code:
.alert {
width: 20em;
background-image: url(C:\Documents and Settings\USER\My Documents\alert.png);
background-color:orange;
margin: auto;
padding: 2em;
}
The url must be a string:
url("C:\Documents and Settings\USER\My Documents\alert.png");
I would guess it's a permissions issue, regardless you will most likely have problems with the URL being a file reference when you move this to a server, I would recommend moving your image into the same location (or better yet an image folder in the root of your site) as your html file and then modify your css to be this
.alert {
width: 20em;
background-image: url('/alert.png'); /* '/images/alert.png' */
background-color:orange;
margin: auto;
padding: 2em;
}
Another way of doing things is to put your text into a div, and set the image as the div's background image using css, like so:
<div class="alert">
<p>
<strong>Alert!</strong>
This is an alert message.
</p>
</div>
And, for the CSS:
.alert {
width: 20em; (Width of entire div, which includes text and bg image)
background-image: url('../alert.png');
background-color: orange;
margin: auto;
padding: 2em;
}
You can see the live JSFiddle example here: http://jsfiddle.net/Cwca22/TdDJY/
Also, in the code above, the background image will tile (repeat) both horizontally and vertically to fill the space of the div. In order to prevent this, you could make the div the same height and width as your background image, or put background-repeat: no-repeat in your css under the .alert class.
Hope this helps and good luck!
Please check your URL, if possible you can use firebug which is addon of firefox, which will definitely help you, by indicating if image has been loaded or not.
Else another solution would be give height to your alert class as follows
.alert {
width: 20em;
background-image: url('/alert.png'); /* '/images/alert.png' */
background-color:orange;
margin: auto;
padding: 2em;
height: /* height of image*/
}
First put your alert.png picture in the same folder as your html file.
Then try this in your CSS file:
body {
background: orange url("alert.png") no-repeat;
}
I think the problem was the "\" in \alert.png
Good luck!
In the original question he had in his css
background-image: url(C:\Documents and Settings\USER\My Documents\alert.png);
I ran into problems with a gallery page that had images as background thumbnails. Any image filename that had spaces would not appear. It was only the fact that one image happened to have underscores in place of spaces and that did appear that I was able to track it down. As there are spaces in his url, this could be the problem. I fixed my problem by using \ to escape any characters like spaces causing the problem. i.e.
A\ space\ in\ the\ filename.jpg
though this might not work in a Windows pathname!
If the image is in the same directory as the script he shouldn't need the full url anyway.

Setting Input Button Background Image Not Working

I'm trying to set an input button's image in a jsp. My code for the button is like so:
<input type="button" name="Unassign" class="btnUnassignHandlerRule" style="width:50px;" />
//setting width inline because it's not working in the CSS
And the CSS code is like so:
.btnUnassignHandlerRule{
background: url(../Images/leftarrow.png) no-repeat;
height: 50px;
margin-top: 15px;
}
My file hierarchy looks like this:
jsp: web/WEB-INF/jsp/myJspPage.jsp
Image: web/Images/leftarrow.png
Please let me know if my code if correct and if my paths are correct as well? Otherwise I don't know why it's not working.
Works for me, made a jsfiddle: http://jsfiddle.net/g5zKz/
Could you show the path to the css File ? So we can look if your in the wrong path !
Change ../Images/leftarrow.png to ../../Images/leftarrow.png if the page and image URLs are as described. By the way, in my test, width: 50px works fine even when placed in the same CSS rule as the other settings.
Please use this css.
input.btnUnassignHandlerRule{
background: url(../Images/leftarrow.png) no-repeat;
height: 50px;
margin-top: 15px;
}