![](/img/trans.png)
[英]asp.net C# how to programmatically change body background-image on Page_Load
[英]How to set background-image to ::before selector in code behind C# ASP.NET
目前,我正在尝试使用c#代码将背景图像设置为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.