[英]How to set background-image to ::before selector in code behind C# ASP.NET
Currently I was trying to use c# 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
. 目前,我正在尝试使用c#代码将背景图像设置为
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.