簡體   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