I want to add an image to be a background of the header, the thing is that I don't want to add an absolute path since I'm doing this on my pc and them is to upload to my server.
should the <?php bloginfo('template_directory'); ?> work in the css? It is not working here.
code:
#branding {
background: url("<?php bloginfo('template_directory'); ?>/images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
No, you can't use PHP within a CSS file.
You can still use a relative path. This example will work if your CSS file and images directory are in the same directory. WordPress knows this is relative to the theme.
#branding {
background: url("images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
If the images directory is in a parent of the CSS file:
#branding {
background: url("../images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
Somehow #developdaly solution did not work for me, but this helped:
.img-div {
background-image: url("wp-content/themes/your-theme/assets/images/your-img.jpg");
}
.img-div {
background-image: url("./assets/images/your-img.jpg");
}
As a SASS/SCSS user, I find the simplest way to solve this problem is to declare the URL as a variable in your .scss file:
$wpLocation: '/wp-content/themes/themename/';
Then reference it like this:
$background: url($wpLocation + "/whateverfile.jpg");
Related
I want to set a background-image, but it doesn't show up on my site. I have tried to set display: block; but that didn't work.
body {
background-image: url("images/other/background.png");
margin: 0;
}
You probably have the wrong path. If your CSS file is inside /css and your image file is inside /image you should use
background-image: url("/images/other/background.png");
.w {
background-image: url('https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg');
}
<button class="w drum">w</button>
I have been trying to use my Atom editor to create background images for my website and it hasn't been working but we I should use it inline on the HTML file, it will work, I won't to use it on the HTML file. I want to keep the file separate from each other. Please I need your assistance
This could fix your issue!
background-size: contain/cover
Contain will scale the image and fit it to inside the button. Cover will cover the whole button. Or you can try background-size: 100% 100%;
.w {
background: url('https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg') no-repeat;
background-size: cover;
width: 70px;
height: 50px;
}
<button class="w drum">w</button>
You have to reload your CSS file manually, Or remove cached data.
If you are programming in PHP,
Do it like this:
<link href="style.css?<?php echo time(); ?>" rel="stylesheet">
Check the location of your image folder, if you are inserting your images(downloaded) in a separate CSS file then your image folder should be inside the CSS folder.
.w {
background-image: url('images/pic.png')
}
I tried everything to make background image display with my local images. I know that I have the correct image location. because if I use content:url(); it works.
Background-image also works with a url image location from the internet. But it will not render with my local image. I have tried every possible location and it will not render.
This is the path to css:
<link rel="stylesheet" href="stylesheets/myCSS.css" type="text/css" media="screen">
my images folder is in the same path as my css folder.
The following is the HTML code:
<div class="col-md-2">
<p>start here</p>
</div>
and now the CSS:enter code here
.col-md-2 .angelhack {
height: 65px;
width: 188px;
display: block;
background-image: url(myPicture.jpg) no-repeat 0px 0px;
z-index: 1;
}
.col-md-2 .angelhack:hover {
background-image: url('http://4.bp.blogspot.com/-SWLJdR2_YzE/TWB-
EvvBWpI/AAAAAAAAA6U/MVtkwJXED88/s320/donkey.png');
}
Before anyone labels this a repeat question, I have searched all the answers to this question on StackOverFlow and have followed all the suggestions and I still cannot get the picture to render. I know the picture is in the correct location because with Chrome and content:url(); the image works. Any suggestions?
Your missing your "" quotes
background-image: url(myPicture.jpg);
With
background-image: url("myPicture.jpg");
try,
background: url("myPicture.jpg");
Also,
Is the image in the same directory as the file referencing it?
Is the image in a directory below?
Is the image in a directory above?
By "below" and "above", I mean subdirectories and parent directories. Relative file paths give us a way to travel in both directions. Take a look at my primitive example:
Here is all you need to know about relative file paths:
Starting with "/" returns to the root directory and starts there
Starting with "../" moves one directory backwards and starts there
Starting with "../../" moves two directories backwards and starts
there (and so on...)
To move forward, just start with the first subdirectory and keep
moving forward
I have used background instead of background-image and it's working fine. and it assumes that pic is in the same folder as your html.
.col-md-2 .angelhack {
height: 65px;
width: 188px;
display: block;
background: url("myPicture.jpg") no-repeat 0px 0px;
z-index: 1;
}
EDIT: Overlooked that the file path for the url wasn't in double quotes.
Change:
background-image: url("myPicture.jpg") no-repeat 0px 0px;
To:
background-image: url("myPicture.jpg");
background-repeat: no-repeat;
Try this and see if it works.
.col-md-2 .angelhack {
background: url("../images/bg.jpg") no-repeat;
//Set your path in the double quote's
}
Your only problem was the way you wrote the background-image
Instead of writing it like this
background-image: url('mypicture.jpg') no-repeat 50px 50px; //the size isn't good there
Do it like this
background-image: url('mypicture.jpg') no-repeat;
background-size: 50px 50px;
It will appear like this
How do I write the right adress, the code is:
.slide1 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg)no-repeat center;
}
How do I put a image from my resource file? I tried background-image: url("pic1.jpg") -that's the right address- and it doesn't work.
What I do is I put the images from a slideshow in css and put a simple cod afterwards in html to display it.
You have to pass a width and a height in order to make it appear. Try it like this:
.slide1 {
background: url('http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg') no-repeat center;
width: 200px;
height: 200px;
}
Edit:
If the image is in the same directory where your css file is, simply use:
background: url('nameOftheFile.jpg') no-repeat center;
Also this thread may be interesting for you: How to go up a level in the src path of a URL in HTML?
First while I was styling the css I realized I didn't create a folder for it, so I decided to create a folder for css. Which I named screen.css but right after creating the css folder my images stopped showing. I have check the spelling and the tag but nothing seems to help. I did change link tag from screen.css to css/screen.css
Everything was working fine until I created a folder for the css so I'm guessing the problem might lay there.
An example of the html
body
{
background: url(images/wallpaper.png);
background-repeat: repeat-y;
margin: 0;
background-color: #e4c17f;
font-family: 'Nova Square',helvetica, sans-serif;
}
#banner
{
width: 900px;
background-color: #a65900;
margin: 0 auto;
height: 150px;
background: url(images/banner.jpg);
}
#footer
{
width: auto;
background-color: #a65900;
height: auto;
background: url(images/name.jpg);
}
You created the folder CSS therefore probably need to reference the images from your CSS relatively to the images folder...
A relative path is the path to a file from the current directory.
-- images
---- wallpaper.png
-- css
---- screen.css
body {
background: #e4c17f url(../images/wallpaper.png) repeat-y;
}
Try this :
The Browser will start looking for the image from the folder where you have kept your css
background: url(../images/wallpaper.png);
It worked! :D
I changed the tag to:
background: #e4c17f url(../images/wallpaper.png);