I'm trying to use the background-image property on a small site I'm making, but to no avail. Here's the code:
body {
background-image: url(/images/Pangolin.png);
background-size: center;
font-family: arial, "Times New Roman", Times, Serif;
color: #fff;
font-size: 32px;
line-height: 20px;
}
I'm 99% certain the path is correct. I've tried putting the path in quotes, but nothing seems to be working.
Random shot here but hell, maybe it'll work.
I'm assuming that you're using BEM file structure here.
I think you're just forgetting to go up a level, try putting two periods before the first forward slash if the images folder is in the root level.
So it'd look like;
background-image: url(../images/Pangolin.png);
use cover for background-size
body {
background-image: url( path to image );
background-size: cover;
}
Related
This is my first question (and first post) on Stackoverflow. Hope to contribute more once I become skilled enough.
Anyway, I'm having trouble understanding why my background image appears when I reference it using css that's inline with my html, but not when I put it in a separate css stylesheet that the html links to.
Here's what my inline css looks like, which works fine:
<style>
body {
background: url('background.jpg') center center fixed;
background-size: cover;
}
</style>
My styles.css file is shown below, which contains the exact same code:
<style>
body {
background: url('background.jpg') center center fixed;
background-size: cover;
}
p {
font-family: 'Helvetica Neue' Helvetica;
font-color: white;
}
h1 {
color: white;
font-family: 'Helvetica Neue';
font-size: 3.5em;
text-align: center
}
.textbox {
background-color: beige;
height: 100px;
width: 100px;
padding: 10px;
margin: 50px auto;
text-align: center;
font-family: 'Helvetica Neue' Helvetica;
font-weight: 200;
}
</style>
...but it no longer shows the background image. Everything else from the css file (paragraph formatting, text size/color, etc.) shows up in the browser just fine.
Also, the html file, css file, and background image are all in the same directory. So I figured I don't need to use "/background.jpg", "../background.jpg", etc. which I've seen suggested in other cases in other posts on Stackoverflow.
I tried to find an answer to this but couldn't find one. Any help is greatly appreciated!
But, in a separate .css file, I typed the exact same code as above, linking to it in the html file by using:
Did you remove the <style> & </style> tags from the CSS file ? For example, like:
body {
background: url('background.jpg') center center fixed;
background-size: cover;
}
These HTML tags are only required around your CSS rules if you're including CSS directly into your HTML.
i need to see your file and folder structure.. makes sure the the stylesheet you are referring is in the same folder where the html is, if so the same code will do.. if you css is in another folder like in css/styles.css than you have to change the link as well as the href of stylesheet to something like ../image.png
the folder structure matters here
Take the style tags out of your .css file.
I have a simple html and css website which was working fine until i updated some content.
The main background is a colour with one image in the top right corner which is in the 'body' div properties. the font family is also in the 'body' properties.
everything else in my website (div layouts, menu bar background image and div back colours etc.) are all displaying ok, but i have no main background and all font is displaying at a small size and as serif when my set font family is san-serif.
body{
min-height:700px;
min-width:900px;
margin: 0;
padding: 0;
color: #000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 100%;
line-height: 1.4;
background-color: #666;
background-image: url(Images/backleave4.png);
background-repeat: no-repeat;
background-position: right top;
}
As its was working just fine before, i assume the issue is that for some reason its not reading all the body properties correctly.If anyone can give me some advice that would be awesome!
Thanks
EDIT:
Over night it somehow fixed itself, for the most part. I don't know what was wrong. Gahh technology!
Your posted CSS is fine. Can you post a link to the website?
Upgrade your #rightwrap to-
background: rgba(255, 255, 255, 0.6);
I think you want to show your background image all over the page.
I was trying to set my page a background image and yet it didn't seem to work the way I expected it to. Here's the code:
body
{
background-image: url("sf.jpg");
background-repeat: no-repeat;
background-size: 100%;
font-family: "Kozuka Gothic Pro", Avenir, sans-serif;
}
I was wondering what went wrong here. Thanks in advance. Note: the image was in the same folder as the file i'm running.
Demo
Just a small change in your code.
body {
background: url("http://i.stack.imgur.com/DUYP4.jpg?s=128&g=1");
background-repeat: no-repeat;
background-size: 100%;
font-family: "Kozuka Gothic Pro", Avenir, sans-serif;
}
Coz background size cannot be 100 it can be cover or contain, and use background instead of background-image and all, use a background-size:cover it will work
body {
background : url (ur image path);
background-size:cover;
width:100%;
//and other necessary code
}
Looks like you have double tab indent bring it all back on tab.
Change the permission of the image to 777 and the image will show up correctly.
I'm learning css and xhtml through a website called html.net. I'm following their instructions while working on my own website. I've just started the CSS tutorials on image background and i am encountering a small but annoying problem. When I do this, everything is fine. Meaning, there are pirate ships all over the place. It looks like the spanish armada.
body {
background-color: silver;
background-image: url("pix/pirateship.jpg")
}
h1 {font-size: 40px; font-family: arial; color:yellow; background-color:#0000a0;}
h2 {color:maroon;}
li {font-size: 20px; font-family: arial; color:#87f717; background-color:#34282c;}
table {color:black; background-color:gray;}
th {color:black;}
But... when i try and follow the next example, this is not showing any image at all.
body {
background-color: silver;
background-image: url("pix/pirateship.jpg")
background-repeat: no-repeat;
}
h1 {font-size: 40px; font-family: arial; color:yellow; background-color:#0000a0;}
h2 {color:maroon;}
li {font-size: 20px; font-family: arial; color:#87f717; background-color:#34282c;}
table {color:black; background-color:gray;}
th {color:black;}
I suspect this has something... actually, I don't know enough to start suspecting. I'm just gonna leave this one to you guys, and hopefully somebody knows the solution.
PS All of that is in a css file in the same folder as the index file. When I try and use any of the no-repeat, repeat-x or repeat-y values all of my pirates vamoose. The regular background image shows just fine when I don't use those.
you're missing a semi-colon after the background-image selector in your second example. If this is an copy and paste of your code, then that missing semi-colon is the problem.
I'm using Bootstrap with Rails and can't get the brackground color and image to show up together. I have a custom CSS stylesheet where I'm trying to edit the body to have a dark background with a small image in the bottom right corner, like this:
body {
padding-top: 55px;
background-color: #2e2e2e;
background-attachment: fixed;
background-image: url('waves.png');
background-repeat: no-repeat;
background-position: right bottom;
}
Problem is that the image doesn't show up, just the background. If I remove the 'background-color' it shows up and looks perfect, but I can't get them together. I know I'm missing something small (probably stupid too). Appreciate the help.
Have you tried this way?
body {
padding-top: 55px;
background: #2e2e2e url(waves.png) right bottom no-repeat;
background-attachment: fixed;
}
make sure the file extension is .css.erb
body {
padding-top: 55px;
background: #2e2e2e url('<%= asset_path('waves.png') %>') fixed no-repeat right bottom;
}
Not sure about the environment you're in, but have you tried !important ? It adds priority in case there are styles with different values applied somewhere later in code.
body {
...
background-color: #2e2e2e !important;
background-image: url('waves.png') !important;
...
}
Try to put the waves.png file in /assets/images and replace url('waves.png') with this:
background-image: image-url('waves.png');
I'm assuming you're using assets pipeline and your CSS file is preprocessed by Sass (the stylesheet filename ends with .css.scss), for more information I suggest you to read the Asset Pipeline Rails Guide.