How can i add a image background to my website?
body {
margin: 0;
background: url(background.png);
background-size: 1440px 800px;
background-repeat:no-repeatdisplay: compact;
font: 13px/18px "Helvetica Neue", Helvetica, Arial, sans-serif;
I did that much but nothing shows up on my page. I'm a CSS beginner.
Updated:
body {
margin: 0;
background-image: url(.../img/background.jpg);
background-size: 1440px 800px;
background-repeat:no-repeat;
display: compact;
font: 13px/18px "Helvetica Neue", Helvetica, Arial, sans-serif;
Put the background url in quotes.
It should be background: url('background.png');
See here for working demo.
You also have an issue with the background-repeat line missing a semicolon in between two statements. If your background is really tiny you won't see it because of that issue.
Just to update on the solution, among the other issues, the background file was being refrenced with .../background.jpg when it should have been ../background.jpg (2 dots, not 3).
isn't the problem the following line is incorrect as the statement for background-repeat isn't closed before the next statement for display...
background-repeat:no-repeatdisplay: compact;
Shouldn't this be
background-repeat:no-repeat;
display: compact;
adding or removing quotes (in my experience) makes no difference if the URL is correct. Is the path to the image correct? If you give a relative path to a resource in a CSS it's relative to the CSS file, not the file including the CSS.
Is your image on the same folder/directory as your css file? If so, your image url is correct. Otherwise, it's not.
If by any chance your folder structure is like so...
webpage
-index.html
-css
- - style.css
- images
- - background.png
then to reference the image on your css file you should use the following path:
../images/background.png
So that would be background: url('../images/background.png');
The logic is simple: Go up one folder by typing "../" (as many times as you need). Go down one folder by specifying the folder you wish to go down to.
Adding background image on html, body or a wrapper element to achieve background image will cause problems with padding. Check this ticket https://github.com/twitter/bootstrap/issues/3169 on github. ShaunR's comment and also one of the creators response to this. The given solution in created ticket doesn't solve the problem, but it at least gets things going if you aren't using responsive features.
Assuming that you are using container without responsive features, and have a width of 960px, and want to achieve 10px padding, you set:
.container {
min-width: 940px;
padding: 10px;
}
If you add the following you can set the background colour or image
(your css)
html {
background-image: url('http://yoursite/i/tile.jpg');
background-repeat: repeat;
}
.body {
background-color: transparent;
}
This is because BS applies a css rule for background colour and also for the .container class.
And if you can't repeat the background image (for esthetic reasons),
then this handy JQuery plugin will stretch the background image to
fit the window.
Backstretch
http://srobbin.com/jquery-plugins/backstretch/
Works great...
~Cheers!
body {
background-image: url(your image link);
background-position: center center;
background-repeat: no-repeat;
background-attachment:fixed;
background-size: cover;
background-color: #464646;
}
For more modularity and in case you have many background images that you want to incorporate wherever you want you can for each image create a class :
.background-image1
{
background: url(image1.jpg);
}
.background-image2
{
background: url(image2.jpg);
}
and then insert the image wherever you want by adding a div
<div class='background-image1'>
<div class="page-header text-center", style='margin: 20px 0 0px;'>
<h1>blabaaboabaon</h1>
</div>
</div>
The problem can also be the ordering of your style sheet imports.
I had to move my custom style sheet import below the bootstrap import.
Related
I have a tileable wood pattern as background in an html page. The background looks perfectly seamless when viewed in Photoshop or any other software, but on the html page it looks discontinuous at the points where my main div element begins and ends.
Here's a preview: http://i.imgur.com/eTQthA2.png
This anomaly persists across different browsers. (I have tested in latest versions of Firefox, Chrome and IE.) What could be the reason behind this?
Let me know if you want to look at a specific part of the code.
Edit:
Solved the problem. When asked to post the CSS I noticed that I used the selectors body, html to apply the background-image. Removing html from the selector did the bit.
CSS:
body, html {
margin: 0;
padding: 0;
font-size: 13px;
font-family: 'Open Sans', sans-serif;
color: #455d76;
background-image: url("images/bg.png");
background-repeat: repeat-x repeat-y;
text-shadow: 0 1px rgba(255, 255, 255, 0.8);
}
First of all whenever asking a question, you should post your code here and not give link to a preview image or your website, because it makes us tough to solve your question.
Coming to your question, from the image it looks like you are using background-image property for different element like say for example div for header, main, and footer, so instead declare that property for body tag instead, in your CSS
body {
background-image: url('whatever.png');
background-repeat: repeat;
}
Fixed the issue. I had used 'body, html' as selector while specifying the background property. Removing 'html' from the selector (ie, leaving just body) did the bit.
(Thanks Mr. Alien, you were right about the background-image property being declared for different elements, ie, body and html in this case.)
Thanks to everyone who answered/commented. :)
I was trying to set a background image in a joomla template in header position, I modified the file template.css and it displayed the background image but not correctly, I could see only the a part on the left and the right of the new backgournd image and the rest is hidden (the white background covered it), I dont know what I did wrong:
Here is the template URL link:
http://vitadorotest.hhc-netzwerk.de/
Here is my CSS coding part :
body.font-size-is-default {
font-size: 13px;
line-height:19px;
color:#8f8f8f;
font-family:Arial, Helvetica, sans-serif;
background:url(../images/background.jpg) 50% 0 no-repeat #fff !important;
height: 95px;
margin: 0 auto;
width: 1087px;
}
this is the real problem,,
white_tail.gif is a while image that cover the the defined id with while background.
#rt-top,
#rt-header,
#rt-menu,
#rt-showcase,
#rt-feature,
#rt-utility,
#rt-breadcrumbs,
#rt-maintop,
#rt-main,
#rt-mainbottom{
background:url(../images/white_tail.gif) 50% 0 repeat-y;
}
just comment it like
/*background:url(../images/white_tail.gif) 50% 0 repeat-y;*/
and see the result.
I added some backgrounds using the added tag on the article home page of http://colorta.com & its working.
<div style="background-image: url(images/banners/myimage.jpg); ">
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
I'm writing a Rails application using Bootstrap. I want to set an image background for it, which I've done using an override.css.scss file. The background displays white when looking at my image, which is in the app/assets/images/ folder.
if I set the image to an external resource, it displays fine.
CSS in override with local image:
html, body {
padding-top: 60px;
background-image: url('app/assets/images/nyc.png');
/* background-repeat: no-repeat; */
background-color: transparent;
height: 1000px;
}
CSS in override with external image:
html, body {
padding-top: 60px;
background-image: url('http://www.google.com/intl/en_com/images/srpr/logo3w.png');
/* background-repeat: no-repeat; */
background-color: transparent;
height: 1000px;
}
Baffling.
Relative URLs in CSS are relative to the to the CSS file, so perhaps you are pointing to the wrong location?
/path/to/app/assets/images/nyc.png
/path/to/style.css
Unless your CSS file lives here, relative to the file in question, you'll be getting a 404 on that image.
i'm making a splash image div that changes the background with different css class, here's rules i defined:
#splash {
height: 130px;
}
#splash.homepage {
background: #F7EECF url("images/splash_home.png") no-repeat 0 0 scroll;
}
#splash.projectspage {
background: #F7EECF url("images/splash_projects.png") no-repeat 0 0 scroll;
}
this works fine in firefox and chrome, but the background somehow doesn't show up in ie 6. The weird thing is, it works for the homepage class but not the projectspage class. so ie 6 seems to interpret these almost identical rule differently. i tried clear the cache, didn't help. i'm quite new to css and ie 6 hacks, so am i missing anythings here?
also another problem that's slightly related to this, it seems it doesn't work in firefox when there is space before the class, like "#splash .homepage", but somehow i see other people's websites using the css with a space. what could be the problem?
update:
i tried to reverse the order of the #splash.homepage and #splash.projectspage, then now projectspage works but not the homepage. It seems whatever is immediately followed by #splash is used.
here are some relevant css & htmls:
#splash {
height: 130px;
}
#splash.projectspage { background: #F7EECF url('images/splash_projects.png') no-repeat 0 0 scroll; }
#splash.homepage { background: #F7EECF url('images/splash_home.png') no-repeat 0 0 scroll; }
#splashtext {
padding: 53px;
height: 40px;
width: 450px;
}
#splashtext h2 {
color: #FFFFFF;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: normal;
font-style: italic;
}
#splashtext p {
color: #FFFFAA;
font-family: Calibri, Arial, san-serif;
font-size: 14px;
font-weight: normal;
margin-top: 10px;
font-style: italic;
}
<!-- splash, this one does not show -->
<div id="splash" class="homepage">
<div id="splashtext">
<h2>some header</h2>
<p>some description</p>
</div>
</div>
<!-- splash, this one shows -->
<div id="splash" class="projectspage">
<div id="splashtext">
<h2>some other header</h2>
<p>some other description</p>
</div>
</div>
IE6 does not support multiple combined selectors to select elements (#id.class or .class.class, etc). IE6 will ONLY recognize the last class/ID in your chain.
Details and example
However, in this case, as long as you only have .homepage and .projectspage on one element on the page, the background image should be showing up on the correct element.
I noticed that you are probably using .homepage and .projectspage to differentiate between two PAGES and the same ELEMENT on those different pages. A good practice is to put the class on the <body> element so you can use it to differentiate each page and their descendants.
<body class="homepage">
<div id="splash">
Then your CSS would be:
body.homepage div#splash { blah }
body.projectspage div#splash { blah }
Added benefit: you can now target any elements on a per page basis, not just the ones that you add ".homepage" or ".projectspage" to.
It's possible you're having an issue with the .png image files. IE6 cannot handle the transparency layer that is part of .png images, it simply renders any pixel with a transparent marker as a grey background.
As for the second part of your question, #splash.background is a significantly different rule than #splash .background. The first one (no space) refers to the element with id splash that also has a background class. The second rule (with a space) refers to any element of class background that is a child of the element with id splash. Subtle, but important difference.
Try taking out the quotes around your URLs in the background specifiers, or changing them to single quotes.
Why are you worried about ie6? Anyway it works in ie7 and ie8.
Are you sure that is not a problem with png? Try with a jpg or gif image.
I would bet that the problem is specifically to do with the IE6 misshandling of .pngs
To test, try replacing these graphics with a gif or jpg and check to see if the selectors are working correctly.
Once you've identified that it is a problem with pngs try using the Supersleight jQuery plugin.
I think using min-height property will sometimes work.
Try the below code.
#splash {
min-height:130px; /* first */
height:auto !important; /* second */
height: 130px; /* third */
}
#splash.homepage {
background: #F7EECF url("images/splash_home.png") no-repeat 0 0 scroll;
}
#splash.projectspage {
background: #F7EECF url("images/splash_projects.png") no-repeat 0 0 scroll;
}
Note: Please use the same order of css in #splash selector.
(I guess your projectspage is under a sub-directory of home-page?)
Try using absolute paths to each image in the CSS (eg. url("/images/splash_projects.png")) - it chould be that IE6 resolves images relative to the containing page instead of the CSS file (depends whether your CSS is inline or in an external file I suppose.)
I've got the same problem, and it's not PNGs.
e.g.
column2menu li { border-bottom : 1px solid;}
column2menu li.goats { border-bottom-color : brown;}
...works in IE6, but...
td#menu { background-repeat:no-repeat;
background-position:bottom right;}
td#menu.goats { background-image :
url(../images/goats.jpg);}
...doesn't.
But I found a solution for ie6 that works so far in FF, i.e.:
.tdgoats { background-repeat:no-repeat;
background-position:bottom right;
background-image : url(../images/goats.jpg);}
...so you use:
...and ie6 is happy
Thsi post looks OK where I'm typing it, but the preview in the blue box is a bit odd.
Somehow lines 2 and 3 got <h1>'d