javascript style.top / left不在div中工作

时间:2017-11-20 19:44:09

标签: javascript

我只想移动修改this.elemento.style.top和this.elemento.style.left的div。

如您所见,首先获取style.top和style.left的值,然后尝试在控制台上手动修改sttyle.top /的值:

>>> this.elemento.style.top 
"48px"
>>> this.elemento.style.left
"18px"
>>> this.elemento.style.top = "500px";
"500px"
>>> this.elemento.style.left = "500px";
"500px"

https://gyazo.com/090bb475a3affc117ea5c729a04b8cf3

当我使用this.elemento时,它只是hmtl中的div。这是一个例子:https://gyazo.com/66503fe34e63deba778fc2da70da8a59

1 个答案:

答案 0 :(得分:1)

我假设你试图给div一个绝对的位置。为此,您需要为其父容器位置提供相对位置。 在你的CSS中加上这个。

curl -H 'Content-Type: application/soap+xml; charset=UTF-8' \
     -H 'SOAPAction: Some-Action' \
     --data-binary @request.xml \
     <endpoint>

如果您更喜欢在JS中执行此操作,请将其添加到您的JS文件中:

#parent{
  position: relative;
}
#child{
  position: absolute;
}