【问题标题】:How to get the div to expand all over the screen even when the background content is modified? [duplicate]即使修改了背景内容,如何让 div 扩展到整个屏幕? [复制]
【发布时间】:2020-09-26 04:26:41
【问题描述】:

即使背景内容发生变化,我也会尝试使跨越整个屏幕的 div 保持扩展。请尝试以下示例。所需的操作是当点击按钮时,带有类窗口的 div 继续覆盖整个屏幕

document.querySelector("button").addEventListener("click", () => {
  document.querySelector("ul").classList.toggle("hide");
});
.window {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: white;
  border: 2px solid goldenrod;
}

ul {
  list-style: none;
  padding: 0;
}

ul li {
  padding: 20px;
}

ul.hide {
  display: none;
}
<div class="window"><button>Click me</button></div>

<ul class="hide">
  <li>Item-1</li>
  <li>Item-2</li>
  <li>Item-3</li>
  <li>Item-4</li>
  <li>Item-5</li>
  <li>Item-6</li>
  <li>Item-7</li>
  <li>Item-8</li>
  <li>Item-9</li>
  <li>Item-10</li>
  <li>Item-11</li>
  <li>Item-12</li>
  <li>Item-13</li>
  <li>Item-14</li>
  <li>Item-15</li>
  <li>Item-16</li>
  <li>Item-17</li>
  <li>Item-18</li>
  <li>Item-19</li>
  <li>Item-20</li>
</ul>

【问题讨论】:

    标签: css


    【解决方案1】:

    这是你想要的吗?

    document.querySelector("button").addEventListener("click", () => {
      document.querySelector("ul").classList.toggle("hide");
    });
    .window {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      background: #fff;
      border: 2px solid goldenrod;
    }
    
    ul {
      list-style: none;
      padding: 0;
    }
    
    ul li {
      padding: 20px;
    }
    
    ul.hide {
      display: none;
    }
    <div class="window"><button>Click me</button></div>
    
    <ul class="hide">
      <li>Item-1</li>
      <li>Item-2</li>
      <li>Item-3</li>
      <li>Item-4</li>
      <li>Item-5</li>
      <li>Item-6</li>
      <li>Item-7</li>
      <li>Item-8</li>
      <li>Item-9</li>
      <li>Item-10</li>
      <li>Item-11</li>
      <li>Item-12</li>
      <li>Item-13</li>
      <li>Item-14</li>
      <li>Item-15</li>
      <li>Item-16</li>
      <li>Item-17</li>
      <li>Item-18</li>
      <li>Item-19</li>
      <li>Item-20</li>
    </ul>

    【讨论】:

    • 实际上没有,我想要的是当背景内容出现时,带有windows类的div会展开,这样背景内容仍然不显示
    • @Mario 立即查看。
    • 确实,虽然我看不到你修改了部分位置固定
    • 其实我之前省略了“背景:#fff”。
    猜你喜欢
    • 2021-09-28
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2013-02-04
    • 2016-11-04
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    相关资源
    最近更新 更多