code/link fails with background image from my computer - html

I'm trying to use a photo (
that I copied the path from) to make my background image. I added an image earlier using the same method to copy the location and it's showing up.background-image:
it's turning blue in the parenthesis.
I'm brand new and have no idea what to do. Any help would be greatly appreciated!
#body{
background-image: url(/Users/samanthagaiser/Basic_portfolio/assets/images/dot-grid.png);
}
when I "follow the link" in cs code it clicks over to the next window where I have the image saved.

Copy and paste image, .CSS file and .html file in one folder. Or if You have just .html file copy image to same folder as .html then change:
body{
background-image: url('./dot-grid.png');
}
Path to image have to be relative to file where You load it.
Bellow examples:
No 1.
CSS: /resources/css/styles.css
Image: /resources/images/image.jpg
CSS in styles.css:
div { background-image: url('../images/image.jpg');
No 2.
CSS: /resources/css/styles.css
Image: /resources/css/image.jpg
CSS in styles.css:
div { background-image: url('./image.jpg');
./ = look for image in same folder where .css file is.
../ = look for image below folder where .css file is.
../../ = loog for image two folders below .css file is.

Related

background images not displaying

My file is setup like this:
main folder
index.html
css
image(folder)
and I've tried
background-image: url("../images/vegies.jpg") no-repeat;
("images/vegies.jpg") no-repeat;
('../images/vegies.jpg') no-repeat;
please, can anyone help me ?
If your files are like:
Food/
index.html
style.css
images/veggies.jpg
If you are inside style.css and you want to reach the pic, the path is ./images/veggies.jpg
If you type ../ your path goes one folder outside, if you start with ./ you start from the same folder you are.

how to add background in Django2.0 using html or css

I want to add an image inside my django homepage, but I always cannot get the correct location of the image file I want(yellow high light)
The picture below are the thing I type so far:
https://i.stack.imgur.com/ecyQu.png
also in the same file
{% load static %}
body {
background-image: url('{% static "/bitcoin.jpg" %}');
}
Do I need static whenever I want to insert image in Django2.0? also,
I see some people open separate static file and some ppl put image inside the templete. I am confused where I should put? How can put the background image inside the html??
thank you so your answering!!!!
update ** this is what I have so far
enter image description here
updat2 ** the only refer to admin file only,
enter image description here
You can use inline CSS just for that case. You already have a .wrapper element, so if you want to put a static served image you'd do something like this:
<div class="wrapper" style="background-image: url('{% static 'default_page/bitcoin.jpg' %}');">
Your content here
</div>
If you want to use in your CSS files, just use the absolute path according to your static configuration. If you serve your static files using /static (that means, the path /static/default_page/bitcoin.jpg is correct and shows you the desired image), you can just put into the CSS something like:
body {
background-image: url('/static/default_page/bitcoin.jpg');
}
Hope that works!
EDIT:
As Thomas said, you've placed the image in the wrong folder (inside templates instead of on your static files folder). Refer to this to configure your project the right way.
You've placed your bitcoin.jpg in the same folder as your templates. Django serves all static file, such as pictures, from the static directory. Only templates go in the template directory. Create a directory called static inside your hompage app, create a directory inside that called default_page, and place your background image there. Restart the dev server, and your image should appear.

ERB file raising 404 when trying to find locally held background image

I am trying to change the background for my play.erb page but I'm struggling to get the image (that is held locally) to show. The page works when using a placeholder image provided online. The error message I am getting is this.
127.0.0.1 - - [06/Mar/2018:21:55:49 +0000] "GET /images/map.jpg HTTP/1.1" 404 515 0.0137
As I understand the 404 reflects the fact that the image can't be found.
I have looked at other SO responses and have tried moving the jpg into the same directory, adding and removing quotation marks and adding the 'public' and 'image' directories, all to no avail.
Can anyone see where I am going wrong? I have added the code and my directory structure below.
Thanks for your time.
#play.erb
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body, html {
height: 100%;
margin: 0;
}
.bg {
/* The image used */
background-image: url("/public/images/map.jpg");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<div class="bg"></div>
</body>
</html>
File structure
Root Directory
lib (dir)
lib(dir)
my_app.rb, views(dir)
views (dir)
index.erb, play.erb, public(dir)
public(dir)
images(dir)
images(dir)
map.jpg
As per http://sinatrarb.com/intro.html there were two key issues with my file structure and code.
1.) Static files are served from the ./public directory.
I adjusted my file structure to this:
Root Directory
lib (dir), public(dir)
lib(dir)
my_app.rb, views(dir)
views(dir)
index.erb, play.erb, public(dir)
Public(dir) still holds the images(dir) and images(dir) still holds map.jpg.
2.) Note that the public directory name is not included in the URL.
I also adjusted the URL to this:
background-image: url("/images/map.jpg");
This solved the problem.
EDIT: Sorry, I didn't see the Sinatra tag on you post... I will leave this only for information, but sorry there I can't help you...
Only for rails:
The problem on your code is that asset-pipeline create a fingerprint after the file name to inform the browser when you update somenthing, you can't have access of folders inside the public folder (You can confirm trying to access the path on the browser: localhost/images/somenthing.*), only the root of it...
You can use the AssetsHelper for do the job for you!
<style>
...
.bg {
/* The image used */
background-image: url(<%= image_path('map.jpg');
...
</style>
If you try to do this on a *.css or *.scss file, rails will give you a error.
The solution for this case is:
*.css - *.scss
.bg {
/* The image used */
background-image: url(asset_path('map.jpg'));
Hope this answers your question :)

How to give image path for background url

I am giving background image to hr tag like this.
<hr style="height:6px;background: url(http://ibrahimjabbari.com/english/images/hr-11.png) repeat-x 0 0;border: 0;margin:0px!important">
Now i have saved the image locally. How can i set the path of my image in the above url.
My folder structure is
In app folder i have css, images, ts.
Inside ts i have html page and the above code.
inside images i have "hr-11.png".I specified path like this.
background: url('../images/hr-11.png').
But its not taking that path and no image is there. How can i correctly give the url path.
This will help you & inside example.html:
<hr style="background:url('../images/hr-11.png') repeat-x top left; border: 0"></hr>
also check with: background-image: url('../images/hr-11.png');
App
|-images
|-css
|-ts
|-example.html
There is a mistake in the path. The correct path should be like: background: url(images/hr-11.png) repeat-x 0 0
There are rules for url routing:
./images will go one level up. which means, if you are in css folder and you have a container folder of content for example, the path will search one level up meaning, content/images.
App
|-content
|-images
|-example.png
|-css
|-example.css
../images will go two levels up, if you are in css folder and you have a container folder of content for example, the path will search two levels up meaning, main_project/images.
App
|-images
|-example.png
|-content
|-css
|-example.css
~/images will search the entire folder for the given file,
for example from MVC:
~/Scripts/angular.js
/ Or non at all - Will search the current main folder:
Html/Index.html
App
|-Html
|-Index.Html

slidify and include picture on title page

because I am new to slidify, maybe doing a mistake
edited : slidify.css
.title-slide {
background-color: #b4f2f2;
background-image:url("C:/download/ibm-db2.png");
}
the color is changed as requested - but the image is not displayed
although the file is in correct location
Directory of C:\download
07/18/2014 08:13 PM 10,315 ibm-db2.png
thanks for all update
best regards, Guy Przytula
Local image works with a relative path from assets folder. For example:
bg:url(assets/img/picture.png)
assets folder is inside your slidify project
Your slidify project:
|
|--index.Rmd
|--index.html
|--assets
| |--img
| |-- picture.png
|
|--libraries
It does not matter where the picture is, but to keep an order you should follow Jorge's advice.
You need to go to this route: and find "slidify.css"
\test1\libraries\frameworks\io2012\css
Look and change this part:
.title-slide {
background-color: #FFFFFF; /* #EDE0CF; ; #CA9F9D*/
background-image:url(D:\\test1\\star-bg.png);
background-repeat: no-repeat;
background-position: center center;
background-size: contain;
/* background-image:url(http://goo.gl/EpXln); */
}
As you see the path to my logo file has "\". This is the path I get when using: file.choose().
If you use RStudio probably you won't see the image loaded. You need to go to the folder where the index.html is and open it on any browser.