javascript - 如何让我的页脚从顶部覆盖页面的 100% 高度和宽度?

标签 javascript html css

我有一个带有页眉、页脚和内容的 html 页面。当用户点击我的页脚时,我希望页脚从顶部开始覆盖整个页面。当我将页脚的高度和宽度设置为 100vh 和 100vw 时。它从底部开始。我如何让它从顶部覆盖? Image of the web page layout

最佳答案

您需要使用 percentage % 而不是 vh/vw/px。您需要设置 top:0;height: 100%(设备屏幕的全高)。

function toggle() {

  var className = document.getElementById('footer').className;

  if (className == 'footer') {
  
    document.getElementById('footer').innerText = 'Click to minimize';
    document.getElementById('footer').className = 'footer full';
  
  } else {
  
    document.getElementById('footer').innerText = 'Click to miximize';
    document.getElementById('footer').className = 'footer';
  
  }


}
.footer {

  background-color: #000;
  color: #FFF;
  width: 100%;
  padding: 20px 0;
  
}

.full {
  height: 100%;
  width: 100%;
  position: fixed;
  top: 0px;
  left: 0px;
}
<h1>My heading</h1>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<p>

  Hello, this click on the footer to expand it.

</p>

<br>
<p>

  Hello, this click on the footer to expand it.

</p>

<br>

<div id='footer' class='footer' onClick='toggle()'>
  Click to maximise
</div>

关于javascript - 如何让我的页脚从顶部覆盖页面的 100% 高度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58741517/

相关文章:

javascript - 如何使用 Google 图表动画制作数值动画?具体是仪表

javascript - 我如何将变量使用到对象名称中(子对象情况)

javascript - document.querySelector 为使用 javascript 注入(inject)的 html 返回 null

html - 如何选择放置在未知级别的元素

css - 一行中的偶数列

javascript - 如何使用 css 中的相对变换制作动画?

javascript - 多个 Javascript 模态

html - 如何使用 HTML Canvas 将半圆形区域划分为彩色段

html - 向右浮动看起来像列表中的一个步骤

javascript - 自动图像缩放?