【问题标题】:Web page structure not staying aligned on zooming网页结构在缩放时未保持对齐
【发布时间】:2021-02-26 20:29:35
【问题描述】:

我无法正确对齐显示我的内容。我使用 html 和 css 制作了一个计时器网络应用程序,但是当我在网页中放大或缩小时,显示结构会变得混乱。外框和内按钮不会一起放大或缩小,放大时按钮也会进入下一行。我附上了它们的外观截图。

Web page on 100%
Zoomed in

我使用弹性盒子来对齐组件 这是我写的代码:

body {
  height: 100vh;
  font-family: "Poppins", "PT sans", Arial, sans-serif;
  background-image: url("bg.jpg");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  background-color: rgba(0, 0, 0, 0.8);
  border-radius: 10%;
  -webkit-box-shadow: 0px 2px 7px 8px rgba(255, 255, 255, 0.40);
  box-shadow: 0px 6px 12px 13px rgba(255, 255, 255, 0.40);
  width: 55vh;
  height: 70vh;
  display: flex;
  flex-direction: column;
}

.image {
  margin-top: 10%;
}

.block {
  display: inline-block;
}

span {
  font-size: 50px;
  color: white;
}

button {
  align-items: center;
  margin: 12px;
  border-radius: 50px;
  font-size: 18px;
  height: 90%;
  padding: 10px 40px;
  z-index: 1;
  cursor: pointer;
  transition: 0.5s;
  position: relative;
}

button:hover {
  color: white;
  background: none;
}


/*.button::before{
    content: "";
    position: absolute;
    left: 0;
    height: 0%;
    width: 100%;
    background: none;
    z-index: -1;
    transition: 0.5s;
}*/
<body>
  <div class="container">
    <div class="image">
      <center><img src="timer.png" width="40%" height="20%" alt="" id="timer">
        <br>
        <span id="countdown"> 60 </span> <span id="plural">s</span>
        <br>
        <div class="block">
          <button id="start" name="start" class="fill" onclick="startTimer()">START</button><br>
          <button id="add" name="+5" class="fill" onclick="add()">+5</button><br>
        </div>
        <div class="block">
          <button id="pause" name="pause" class="fill" onclick="pauseTimer()">PAUSE</button> <br>
          <button id="remove" name="remove" class="fill" onclick="remove()">-5</button> <br>
        </div>
        <div class="block2"><button id="end" name="" class="fill" onclick="endTimer()">END</button></div>

      </center>
    </div>
    <!-- <div class="text"></div> -->
    <div></div>
  </div>
  <script src="index.js"></script>
</body>

我刚开始,所以任何帮助都会很棒。谢谢!

【问题讨论】:

  • 缩放的期望结果是什么?一切都变大了还是一切都保持不变?
  • &lt;center&gt; 是一个过时的元素,不应再使用。
  • @MikeB 按钮和框随着比例减小而增加

标签: html css forms button flexbox


【解决方案1】:

我对您的目标有所猜测,但如果我理解正确,.container 上的高度和宽度值会导致您出现问题。我删除了它们,并将 &lt;center&gt; 替换为 &lt;div&gt;,正如 Paulie 评论的那样,它已经过时了:

body {
  height: 100vh;
  font-family: "Poppins", "PT sans", Arial, sans-serif;
  background-image: url("bg.jpg");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  text-align: center;
  background-color: rgba(0, 0, 0, 0.8);
  border-radius: 10%;
  -webkit-box-shadow: 0px 2px 7px 8px rgba(255, 255, 255, 0.40);
  box-shadow: 0px 6px 12px 13px rgba(255, 255, 255, 0.40);
  display: flex;
  flex-direction: column;
}

.image {
  margin-top: 10%;
}

.block {
  display: inline-block;
}

span {
  font-size: 50px;
  color: white;
}

button {
  align-items: center;
  margin: 12px;
  border-radius: 50px;
  font-size: 18px;
  height: 90%;
  padding: 10px 40px;
  z-index: 1;
  cursor: pointer;
  transition: 0.5s;
  position: relative;
}

button:hover {
  color: white;
  background: none;
}
<body>
  <div class="container">
    <div class="image">
      <div><img src="timer.png" width="40%" height="20%" alt="" id="timer">
        <br>
        <span id="countdown"> 60 </span> <span id="plural">s</span>
        <br>
        <div class="block">
          <button id="start" name="start" class="fill" onclick="startTimer()">START</button><br>
          <button id="add" name="+5" class="fill" onclick="add()">+5</button><br>
        </div>
        <div class="block">
          <button id="pause" name="pause" class="fill" onclick="pauseTimer()">PAUSE</button> <br>
          <button id="remove" name="remove" class="fill" onclick="remove()">-5</button> <br>
        </div>
        <div class="block2"><button id="end" name="" class="fill" onclick="endTimer()">END</button></div>

      </div>
    </div>
    <!-- <div class="text"></div> -->
    <div></div>
  </div>
  <script src="index.js"></script>
</body>

【讨论】:

  • 如果我移除容器尺寸,盒子会变得比我想要的更宽。我将如何解决这个问题?
  • 尝试添加宽度,而不是高度,因为这是导致问题的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多