简体   繁体   中英

Set Background image in CSS

I have the following code in my JavaScript&CSS to create a div & set a bg image :

var incrementEnabled = document.createElement('div');
incrementEnabled.className = "SchedMainCtrlIncrementBtn_En"; 
this.divElt.appendChild(incrementEnabled);

.SchedMainCtrlIncrementBtn_En {
background-color: white;
float:left;
position: fixed;
width:230px;
height:65px;
top:125px;
left:360px;
background:url("../images/icons/IcnListAddRecipient_En.png") no-repeat center;

path of url is also proper but image is not getting set.

Thanks
Sneha

You should not use url("../images/icons/IcnListAddRecipient_En.png") but url(../images/icons/IcnListAddRecipient_En.png)

Replace css with this and I hope the problem will be solved

.SchedMainCtrlIncrementBtn_En {
background-color: white;
float:left;
position: fixed;
width:230px;
height:65px;
top:125px;
left:360px;
background:url(../images/icons/IcnListAddRecipient_En.png) no-repeat center;

Did you check with firebug (or any other developer tools in your favorite browser) what happens?

  • does your div show up at all?
  • is the class correctly set?
  • what happens to the background attribute?

And why are you using float AND position:fixed? The float:left doesn't do anything.

And btw, I always use single quotes, it's just fine using them :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM