开发者

Is runat="server" required for HTML tags which have CSS style built by ASP.NET?

开发者 https://www.devze.com 2023-01-21 05:58 出处:网络
I got this div tag who\'s background image\'s being set in the CSS using s开发者_Go百科ome method like this..

I got this div tag who's background image's being set in the CSS using s开发者_Go百科ome 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)

0

精彩评论

暂无评论...
验证码 换一张
取 消