user1551482
user1551482

Reputation: 529

adding an background to a div without having text?

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

Answers (3)

Curtis
Curtis

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

user657496
user657496

Reputation:

Thats because the div is 0x0px. Give it a height and a width.

Upvotes: 1

Abraham
Abraham

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

Related Questions