Search code examples
cssasp.net.netwebformsmarkup

setting background or background image of a div in asp.net webforms


i have a the following code for a following image path in web project of visual studio solution

 Folder1\Images\banner.png'


<div id="placeholder">

</div>

and the css to set the background for this is

 #placeholder { 
    position:relative;
    width: 40em;
    margin:auto;
    height:4em;
    margin-top: -1em;
    padding-top: 2em;
    background-image:url('../folder1/Images/banner.png');    
    /* background('('../folder1/Images/banner.png') */
    background-size: 40em;
    background-repeat:no-repeat;    
    clear: right;
    }

I also tried with ~ instead of ../ symbol but it doesnt work.

Should i use background-image or background attribute to set the background image of the div. whichever attribute i use i don't get any image in the background. please help.


Solution

  • You need a add a width and a height of the background image for it to display properly.

    So you want something like

    #placeholder { 
        background-image:url('../folder1/Images/banner.png');    
        height: 100px;
        width: 100px;
    }