BG image from web works but folder image doesn't - css

I'm taking a course on Udemy and I've followed what it shows in the lesson and even asked in discord but haven't received a solution.
The background image I used from the web using a image URL works, but when I try to link an image saved on the same folder as the CSS and HTML files nothing happens. All I get is a blank white background instead of an image. I'll be adding screenshots.
https://imgur.com/gallery/C4468Kb
body {
background-image: url(starwars.jpg);
background-size: auto;
}
h2 {
color: red;
text-align: center;
border: 5px solid purple;
cursor: crosshair;
}
p {
color: pink;
}
p {
color: green;
}
li {
list-style: none;
display: inline-block;
}

Try background-image: url('starwars.jpg');

Check the file path for the image and make sure it reflects what is being written in your url() css. Right now you are showing that image is located in the root directory of your project. If the image is not in the root directory, say for example it's in a folder called "images" in your root, then the url should read url('images/starwars.jpg').
It would be good practice to put any image you want to use in your site in a folder named "images" inside your root directory anyway. Try that, and see if it works.
So just to clarify: create a new folder inside the root folder of your project. It should be on the same hierarchical level as your index.html file. Take the image, where ever it is, and place it inside that new images folder. Change your css to say
background-image: url('images/starwars.jpg');

Related

Using background images in jade

I'm using express + node.js + Jade. I wrote up a jade file but I can't get the background image to appear. I played around with the body class and it seems to work for the text color but it doesn't use the background image
body {
font-family: "Josefin Slab" !important;
background-image: url("concursum-bg.jpg");
background-size: cover;
color: white;
text-align: center;
background-repeat: no-repeat;
}
I made sure that the image is in the same folder as this jade file.
When I do view page source the html is:
body {
font-family: "Josefin Slab" !important;
background-image: url("concursum-bg.jpg");
background-size: cover;
color: white;
text-align: center;
background-repeat: no-repeat;
}
I'm running this on localhost if that matters.
The image file must be served so that it is accessible to the browser. When it's in the folder with the jade file (I'm assuming this is a views directory), it's not served by Express and so the browser can't get to it. To fix this, make the server serve the image file:
In the main Express app, use express.static to serve static files from a directory:
app.use(express.static(__dirname + "/public"));
Now, create the directory for the files to be served from:
mkdir public
Create an image directory there, for sanity:
mkdir public/images
Move the file there
mv {views,public/images}/concursum-bg.jpg
Update your stylesheet, changing url("concursum-bg.jpg"); to url("/images/concursum-bg.jpg");.
Restart your Express app.
http://expressjs.com/starter/static-files.html

css background-image will not work

I've been patient with this, it is..
aside{
width: 300px;
margin: 0 10px 10px 0;
padding: 5px;
background-image:url ("images/simple_dashed_#2X.png");
position:relative;
float: right;
height: 800px;
border: solid #002222;
color: #bab1b1;
text-align:center;
}
the images folder is in the same folder as the .html file. I did also try (".../images/simple_dashed_#2X.png") I have also checked and rechecked the name of the picture it's correct capitalization and all. It just shows nothing.
It sounds from your overall level of confusion over the problem that you are not using your Chrome developer tools properly.
You can use the Inspector to determine beyond a shadow of a doubt if the image is not loading, is simply off screen, etc.
Please watch this video where JavaScript's Batman, Paul Irish, explains:
http://www.youtube.com/watch?v=O3W1yuq-ZlE
I guarantee you will be able to solve the problem on your own after watching this video for about 20 minutes.
Image references are relative to the CSS file, not your HTML document. Can you adjust your image path accodingly?
So, if your files are laid out like:
/
page.html
/assets
/CSS
styles.css
/images
simple_dashed_#2X.png
your style should be:
background-image:url ("../../images/simple_dashed_#2X.png");
Replace
background-image:url ("images/simple_dashed_#2X.png");
with
background-image:url("images/simple_dashed_#2X.png");
Get out the space after url, and it should work again.
Js fiddle-> http://jsfiddle.net/niteshp27/XMUmq/

CSS Content URL image is broken

I am trying to display images within a table cell with css. This is what I have:
HTML:
<td class="activity-status status_not_started">Not Started</td>
CSS:
td.activity-status {
font: 0/0 a !important;
color: transparent !important;
width: 80px !important;
padding: 0 !important;
}
td.status_major_issues:after {
content: url(/sites/ih/Style%20Library/org-ih/img/status_major_issues.png) !important;
}
In the browser, when I visit
http://myspsite/sites/ih/Style%20Library/org-ih/img/status_major_issues.png
The image is shown just as expected.
However, in the web page after the css is applied the image appears broken.
The path to the page is:
http://myspsite/sites/ih/46/Pages/status.aspx
The path to the css file is:
http://myspsite/sites/ih/Style%20Library/ih-status/css/style.css
Anybody an idea what could be going on?
Thanks!
Eric
Your css is probably in a separate directory thus the path to the content should be like
content: url('../sites...')
You have to move up one directory, because the path is taken from where the css file is, not where the scripts of the page are.

background image in rails

I have rails 3.2.9 and I want to put a background image. my image is found in the folder: public/images and I put it also in the folder: assets/images.
ul {
height: 200px;
width: 350px;
border: solid 1px blue;
margin: 0 auto;
padding: 0px;
background-image: url('/images/todo.png');
}
but there is no backgound image.
please help.
I have to put:
background-position: center;
so my code is:
background: url(/assets/rsz_todo.png) no-repeat;
background-position: center;
and my image is found in assets/images
A simple way to check (before you edit your css) is to enter the path in the browser. This way your are sure what the path should be.
Your app/assets/images folder maps to:
http://domain/assets/
So if you have a app/assets/images/logo.png you should be able to retrieve that in your browser like:
http://domain/assets/logo.png
Then, in your CSS you should be able to refer to your logo.png like:
// app/stylesheets/application.css
body {
background: url(/assets/logo.png) no-repeat;
}
Also have a look at the Rails asset Pipeline:
http://guides.rubyonrails.org/asset_pipeline.html
In case this helps anyone finding this...Rails provides helper methods for referencing an asset in your CSS or SASS file:
background-image: image-url("rails.png")
Turns into...
background-image: url(/assets/rails.png);
Why don't you try just :
background: url(image.png)
The asset-pipeline is made up for simplicity.
If you put your image in assets/images then when calling that image you should use
background-image:url("/assets/image.png");
or you could try
background:url("/assets/image.png");
And sometimes i have found using background rather than background image works better, but that is just personal experience

how do i reference an image from my css in asp.net-mvc on a hosting provider

i have this inside my site.css file (in the COntent directory)
body { width: 100%; background: #e7e6de url("/content/images/back-page1.png") repeat-x; font: normal 13px arial, sans-serif; text-align: center; color: #4c4c4c; }
it works fine when i test it locally but it doesn't work when i upload the site to the hosting provider.
the issue is around the url of the background image. i assume its some path issue.
any suggestions?
You need to make the URL relative to the css file.
If your css file is located under content/style
Then your url should be ../image/back-page1.png

Resources