Reputation: 529
im trying to make an html element have a background image using css, but the background doesn't without having text for example.
CSSS -
#box {
background url(.....)
}
HTML -
<div id="box">something</div> // this works bu it shows the text
<div id="box"></div> // this is what i want not text just the background url from #box
thanks :))
Upvotes: 0
Views: 67
Reputation: 103368
Your div has an auto
height by default. The reason you are only seeing the background when text is entered into the div
is because the auto
height is being increased from 0px
to whatever height is now required now there is text in place.
Therefore if you need a fixed height, you need to set a height
property in your CSS:
#box
{
background: url(.....);
height:100px;
}
You don't need to set a width as this will automatically be auto
width by default.
Upvotes: 0
Reputation: 20694
Set a width and height on the div.
Example:
HTML:
<div id="myDiv"></div>
CSS:
#myDiv {
background: url(path/to/image.png);
width: 200px;
height: 200px;
}
Upvotes: 1