【问题标题】:How do I make my Vue webpage fill the entire viewport?如何让我的 Vue 网页填满整个视口?
【发布时间】:2021-03-03 13:31:06
【问题描述】:

我正在使用一个通过 Vue CLI 使用 Vue 3、Vue Router 和 Bootstrap 构建的演示 Web 应用程序。不幸的是,我无法让我的网页填满浏览器窗口的整个高度。

我尝试使用引导程序在最高级别的 div 上设置 vh-100,但它似乎仍然垂直匹配内容的最小高度,而不是消耗整个可见视口高度。

如何让我的应用布局遵循 Bootstrap 的 vh-100 属性?

App.vue

    <template>
  <router-view/>
</template>

<script>

export default {
  name: "App"
}
</script>

LoginPage.vue

<template>
  <div class="vh-100 container" id="app">
    <div class="row vh-25">
      <div class="image-container row justify-content-center align-items-center">
        <img src="../assets/images/pic.png" alt="picture">
      </div>
    </div>
    <div class="row vh-75">
      <EmailForm/>
    </div>
  </div>
</template>

<script>
import EmailForm from '@/components/EmailForm.vue'; // @ is an alias to /src

export default {
  components: {
    EmailForm,
  }
}
</script>

<style>
.container {
  margin: 0;
  background: url(~@/assets/images/background_pic.jpg) repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
.image-container {
  position: relative;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  text-align: center;
}

img {
  padding: 0;
  display: block;
  margin: 0 auto;
  max-height: 60%;
  max-width: 60%;
}
</style>

【问题讨论】:

  • 您使用的是 bootstrap 4.1 或更高版本吗?
  • 是的,我使用的是 bootstrap 4.5.3

标签: css vue.js bootstrap-4 vue-router vuejs3


【解决方案1】:

有很多方法可以做到这一点。在 Vue 中,#app 通常是最高级别,因此您可以在那里设置最小高度。

#app {
  min-height: 100vh;
}

或者您可以将.container 元素设置为固定位置并覆盖视口。

.container {
  position: fixed;
  top:0;
  right: 0;
  bottom: 0;
  left: 0;
}

这完全取决于你想要做什么。

【讨论】:

  • 很好,这似乎可行,但是当我使用第一个解决方案 (#app) 时,我的整个背景周围有一个边距,并且页面可以稍微滚动。这是什么原因造成的?
  • 很难说是什么导致了间距问题而无法看到整个内容,但您可能希望在正文和 #app 元素上设置 margin: 0; padding:0
  • margin: 0 and padding: 0#app#body 元素上设置时没有解决问题。除了我的问题中的代码之外,您还需要查看什么来确定添加边距的位置?
猜你喜欢
  • 1970-01-01
  • 2015-08-23
  • 2015-05-16
  • 1970-01-01
  • 2021-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-13
相关资源
最近更新 更多