Doe Doe - 1 year ago 115
CSS Question

Can't put image behind text in html and css

I'm working with a html and css project. I want to create a box for text which has an image in background like in this image:
enter image description here
The result I get is this:
enter image description here

.background {
background: url(background.png) repeat;
border: 2px solid black;
z-index: -1;
width: 100%;
height: 100%;
position: relative;
opacity: 0.4;
-webkit-filter: sepia(100%);
/* Chrome, Safari, Opera */
filter: sepia(100%);
div.transbox {
margin: 30px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
filter: alpha(opacity=60);
/* For IE8 and earlier */
div.transbox p {
margin: 5%;
font-weight: bold;
color: #000000;

<div class="background">

<div class="transbox">
<p>This is some text that is placed in the transparent box.</p>

Is there something I should change in my code? My image
exists in the folder where I have the html file. Thanks!

Answer Source

When you use this in your css file:

background: url(background.png) repeat;

That means the image is in the same folder as the css file.

if the image is in a folder upper of the css file, use this"

background: url('../background.png') repeat;

Also, if you are trying on a Linux OS, care about the upper/lower cases of name of files

Thanks @StephenP for putting the complete message:

paths in CSS files are relative to the style sheet, not relative to the document

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download