繁体   English   中英

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

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

目前,我正在尝试使用代码将背景图像设置为div但是当我尝试将背景图像放入div并使用div id将样式设置为:before时,此操作不成功。

这是我的代码:

CSS代码:

#theme1:before {

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

ASPX代码:

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

C#代码:

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

任何帮助,将不胜感激。 谢谢!

尝试使用attribute.add代替样式,例如。

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

那应该工作

暂无
暂无

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

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