![](/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.