定位的位置设置,是top和left,bottom和right定位的看下:http://www.w3school.com.cn/css/pr_class_position.asp你设置的marginTop和marginLeft,是外边距。
http://www.w3school.com.cn/css/css_margin.asp赶紧补基础知识。
http://www.w3school.com.cn/css/css_margin.asp赶紧补基础知识。
解决方案 »
- Jquery中的$.map(),$.each(),$.preg()的区别与关系
- Math.random()纠结
- 菜鸟请教:关于弹出DIV关闭时如何刷新原页面
- js 控制MediaPlayer 播放 点击不能实现自动播放
- 怎么得到选中的文本的字体信息?
- 关于zhaoxiaoyang的右键弹出菜单能否改成xp样式?
- 表单中有多个文本字段,个数不能确定,怎么用JS进行数据验证呀!
- 问一个简单的问题,关于停止javascript运行
- 能否改变用 javascript 的 alert 函数弹出的对话框中的图标?!(在线等待)
- 后退以后,如何得到后退窗口输入框的焦点 和如何改变IFRAME src 两个问题!
- jquery Easy UI 的datagrid的时候遇到问题了,大神们请帮忙看下
- 求登录页面JS代码
把你的marginLeft改成left,
marginTop改成top。
position:absolute;
top:0px;
left:0px;
margin-left:10px;
margin-top:10px;这个效果 可能就是 楼主想要的
#p1c top:30px; margin-top:50px;
http://www.w3schools.com/css/css_boxmodel.asp<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
#p1 {
width:200px;
height:150px;
background-color:#ee9;
position:relative;
}
#p1c {
width:50px;
height:50px;
background-color:#55e;
margin-top:50px;
position:absolute;
top:30px;
}
#p2 {
width:200px;
height:150px;
background-color:#ea9;
position:relative;
}
#p2c {
width:50px;
height:50px;
background-color:#55e;
margin-top:50px;
position:absolute;
top:80px;
}
</style>
</head>
<body><div id='p1'>
<div id='p1c'></div></div>
<div id='p2'>
<div id='p2c'></div></div>
</body>
</html>
Margin - Clears an area around the border. The margin does not have a background color, it is completely transparent
是clear
不是occupy.所以说是可共用的。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><body>
<div id="player-container" onclick="actClick();" style="width:560px;height:560px;position:relative;border:1px #CCC solid;margin-left:auto; margin-right:auto;">
<img id='img1' style="position:absolute;z-index:8;margin-left:188px;margin-top:60px;width:25px;height:25px;background-color:gray;" src="images/img1.png" />
</div>
</body></html>
<script language="JavaScript" type="text/javascript" >
var i=1;
function actClick()
{
var sId=document.getElementById("player-container");
var img1=document.getElementById("img1");
//动态创建img2
var temp = document.createElement("img");
i+=1;
temp.id = "img"+i;
sId.appendChild(temp);
var img2=document.getElementById(temp.id);
// 设置img2属性
img2.position="absolute";
img2.style.zIndex=i;
img2.src="images/img2.png";
img2.style.width='60px';
img2.style.height='60px';
img2.style.left='188px';
img2.style.top='60px';
//img2.style.marginLeft="88px";
//img2.style.marginTop="60px"; img1.style.width='25px';
img1.style.height='25px';
img1.style.marginLeft='188px';
img1.style.marginTop='60px';
}
</script>