簡體   English   中英

如何在asp.net代碼后面將背景圖像設置為非平鋪

[英]How to set background image to non-tiling in asp.net code behind

這是我用來在后台顯示圖像的代碼,但它是重復和平鋪的。 如何在后面的代碼中將圖像設置為非平鋪? 我從不使用CSS顯示背景圖片:

   protected void Image_Selection_Change(object sender, EventArgs e)
    {

        //PageBody.Attributes["bgColor"] = System.Drawing.Color.FromName(DropDownList1.SelectedItem.Value).Name;
        if (DropDownList1.SelectedItem.Text == "Ant and the Grasshopper")
        {
            PageBody.Attributes.Add("style", "background:url(images/ant-and-grasshopper.jpg);");
            PageBody.Attributes.Add("body", "background-repeat: no-repeat"); 
            Session["Background"] = "background:url(images/ant-and-grasshopper.jpg);";
            ImageButton9.Visible = false;
            ImageButton11.Visible = true;
        }

        if (DropDownList1.SelectedItem.Text == "Food Fit for the King")
        {
            PageBody.Attributes.Add("style", "background:no-repeat,background:url(images/King.jpg);");
            Session["Background"] = "background:url(images/King.jpg);";
            ImageButton11.Visible = false;
            ImageButton9.Visible = true;
        }

   }   

我嘗試了后台重復:不重復,但無濟於事。 提前致謝。

"background:no-repeat,background:url(images/King.jpg);"

必定是

"background: url(images/King.jpg) no-repeat;"

除非特殊處理逗號,否則兩個背景屬性之間的逗號不會將它們分開。 只有分號可以做到這一點。 同樣,具有兩個背景屬性也會導致它們發生沖突。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM