简体   繁体   English

如何在C#ASP.NET背后的代码中将背景图像设置为:: before选择器

[英]How to set background-image to ::before selector in code behind C# ASP.NET

Currently I was trying to use code to set background image to div but it was unsuccessful when I try to put the background image into div and use the div id to set the style to :before . 目前,我正在尝试使用代码将背景图像设置为div但是当我尝试将背景图像放入div并使用div id将样式设置为:before时,此操作不成功。

Here is my code: 这是我的代码:

CSS code: CSS代码:

#theme1:before {

   width: 106px;
   content: " ";
   position: absolute;
   left: -16px;
   top: -6px;
   height: 100px;
}

ASPX code: ASPX代码:

<div id="theme1" runat="server">
     <div id="theme2" runat="server">
         hello <br/>
     </div>
</div>

C# code: C#代码:

protected void Page_Load(object sender, EventArgs e)
{
    theme1.Style["background-image"] = "Pic/img.jpg";
    theme2.Style["background-image"] = "Pic/img1.png";
}

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

Try using attributes.add instead of style eg. 尝试使用attribute.add代替样式,例如。

theme1.attributes.add('style', 'background-image(image path)') theme1.attributes.add('style','background-image(image path)')

That should work 那应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 asp.net C#如何以编程方式更改Page_Load上的正文背景图像 - asp.net C# how to programmatically change body background-image on Page_Load 使用ASP.Net和C#在代码中将Data URI设置为asp:Image - Set Data URI to asp:Image in code behind using ASP.Net and C# ASP.NET C#从Code Behind设置OnSelectedIndexChanged - ASP.NET C# Set OnSelectedIndexChanged from Code Behind 如何在asp.net代码后面将背景图像设置为非平铺 - How to set background image to non-tiling in asp.net code behind 如何在ASP.NET中以C#作为代码,以编程方式设置(使用GET SET属性)“ httpRuntime maxRequestLength” - How to programmatically set (using GET SET property) “httpRuntime maxRequestLength” in ASP.NET with C# as code behind 如何在javascript中设置asp.net隐藏字段并访问c#代码后面的值 - how to set asp.net hidden field in javascript and access the value in c# code behind 设置文字 <p> 从c#asp.net中的代码嵌入在asp:Panel中 - Set text in <p> embedded in asp:Panel from code behind c# asp.net 如何设置背景无颜色ASP.NET C# - How To Set Background None Color ASP.NET C# 从数据库中检索图像并将其设置为asp.net mvc5中的background-image属性css - Retrieve image from database and set it to background-image property css in asp.net mvc5 ASP.NET - 未调用隐藏代码 (C#) - AutoEventWireup 设置为 True - ASP.NET - Code behind (C#) not being called - AutoEventWireup is set to True
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM