문제

I got this div tag who's background image's being set in the CSS using some method like this..

Inline CSS:-

.id0, .mySprite:hover div
    {
        background-image: url(<%=GetImage()%>);
        background-repeat: no-repeat;
        width: 728px;
        height: 243px;

    }

HTML:-

<div class="id0"></div>

Now do I need to set runat="server" in this div tag or not? Coz it's not giving no error but was wondering may be I need to coz the image's path's being fetched from code behind...the image's not appearing in this user control.

도움이 되었습니까?

해결책

Well,

  • The "Runat=Server" is not needed at all. The CSS is loaded/associated on the client (in the brwoser) anyway.
  • Sorry, dude, but .CSS files are not evaluated by ASP.NET - so basically, the "url" that the browser gets is <%=GetImage()%>, which obviously the browser can not do anything with.

Result: Does not work. Can not work.

다른 팁

Why do you need the server to generate the path? The image path should be relative to the css file so if your css is in project/css/style.css and image is in project/images/myimage.jpg use

background-image: url(../images/myimage.jpg);

Also, use firebug to check what's really being set as the background image. You can also try

background-image: url(../images/myimage.jpg) !important;

You are generating the css from server-side code? Or is a simple .css file? If you have .css file the code: background-image: url(<%=GetImage()%>); does not work.

And then, the css rule for div with id id0, you must define it with # not dot (#id0 not .id0)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top