繁体   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