【问题标题】:How can i change div position by javascript如何通过javascript更改div位置
【发布时间】:2016-06-18 06:28:28
【问题描述】:

可以改变 div 的位置(通过 css 绝对或相对),但使用 java 脚本

代码示例

<div id="podpis" margin-top="2">
      <div class="invoice-signature">
        <span><?=$xml->sanitize($invoice['Invoice']['user_name'])?></span><br/>
        <span>First name and second name osoby uprawnionej do wystawiania faktury</span>
      </div>

      <div class="invoice-signature">
        <span><br/></span><br/>
        <span>First name and second name</span>
      </div>

      <div clear="both"/>
    </div>

我想改变 div id="podpis" 的位置。

感谢您的回答!

【问题讨论】:

  • 为什么投反对票?这绝对是一个示例问题。他清楚地说明了他想要做什么(“我想改变div id="podpis" 的位置”),并提供了示例代码,以便我们知道我们在看什么。不知道那里出了什么问题。

标签: javascript


【解决方案1】:

设置位置值:

document.getElementById('podpis').style.position = 'relative';

document.getElementById('podpis').style.position = 'absolute';

根据您的 cmets,我觉得无论如何您都希望 podpis 留在页面底部?

//div stays in same place on screen no matter what, even when scrolling
document.getElementById('podpis').style.position = 'fixed';
//div goes to the bottom of the page
document.getElementById('podpis').style.bottom = '0';

【讨论】:

  • 现在需要做的就是你放标签 并复制/粘贴第二个选项,当我放 20 时,它距离底部 20 像素?跨度>
  • 好的问题我解决了。感谢您的帮助和建议。
  • 很高兴知道它有帮助!
【解决方案2】:

是的,您可以使用:

<script>
   document.getElementById('podpis').style.position = 'absolute';
   document.getElementById('podpis').style.position = 'relative';
</script>

希望这会有所帮助。

【讨论】:

  • 好的,你能不能给我准备好的代码,因为我真的不懂java。我询问 java 解决方案,因为我的应用程序 css 被阻止。
  • 您必须在我的答案中添加标签,在您的 html 页面中、head 标签内或&lt;/body&gt; 之前,这取决于您何时想要更改位置。
  • 但是我必须把 top 放在哪里。左或 x , y 。把潜水放在我想要的地方
  • 我想把这个 div 放在页面底部。
  • @kancer “好的,你能不能给我准备好的代码” Stack Overflow 应该是一种帮助你学习解决问题的方法。不是免费的代码编写服务。
猜你喜欢
  • 2020-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-18
  • 2012-03-11
相关资源
最近更新 更多