我的代码: System.Web.UI.WebControls.Image newImage = new System.Web.UI.WebControls.Image();
newImage.ID =i.ToString() + "_" + ii.ToString();
newImage.Style.Add("position", "absolute");
newImage.Style.Add("left",left.ToString());
newImage.Style.Add("top","35");
生成的HTML代码如下:<div id="line1_Panel1" style="height:160px;width:800px;background-image:url(LinesPic/b.jpg);">
<img id="line1_0_0" src="IMG/YellowFlash.gif" style="height:14px;width:14px;border-width:0px; position:absolute;left:12;top:35;" />
<img id="line1_0_1" src="IMG/YellowFlash.gif" style="height:14px;width:14px;border-width:0px; position:absolute;left:36;top:35;" />
在html的div层上没有任何镶嵌层,未用任何css 请问我的img显示出来为什么在div的左上角???也就是他的位置限定失效??
newImage.ID =i.ToString() + "_" + ii.ToString();
newImage.Style.Add("position", "absolute");
newImage.Style.Add("left",left.ToString());
newImage.Style.Add("top","35");
生成的HTML代码如下:<div id="line1_Panel1" style="height:160px;width:800px;background-image:url(LinesPic/b.jpg);">
<img id="line1_0_0" src="IMG/YellowFlash.gif" style="height:14px;width:14px;border-width:0px; position:absolute;left:12;top:35;" />
<img id="line1_0_1" src="IMG/YellowFlash.gif" style="height:14px;width:14px;border-width:0px; position:absolute;left:36;top:35;" />
在html的div层上没有任何镶嵌层,未用任何css 请问我的img显示出来为什么在div的左上角???也就是他的位置限定失效??
left:36;top:35/>
偏移的有点小,效果不明显,你修改大一点数字试试
<img id="line1_0_0" src="IMG/YellowFlash.gif" style="height:14px;width:14px;border-width:0px; margin-top:35px;margin-left:12px;" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">注释掉试下
newImage.Style.Add("top","35");改为
newImage.Style.Add("top","35px");
不用注释上面的东西,直接在添加Style的时候加上像素单位就可以了