css - 如何让我的 Vue 网页填满整个视口(viewport)?

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

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

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

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

应用程序.vue

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

<script>

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

登录页面.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>

最佳答案

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

#app {
  min-height: 100vh;
}

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

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

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

关于css - 如何让我的 Vue 网页填满整个视口(viewport)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64924286/

相关文章:

css - 如何在不更改框列表高度的情况下仅在悬停时显示截断的文本?

css - 防止 XML 列在标记为空时折叠

html - 了解 CSS 选择器优先级/特异性

javascript - 将 anchor 标记样式应用于文本和图像

javascript - CSS 背景色有效性

javascript - VueJS v-for 类交替

html - Bootstrap 无法与 visual studio 2017 一起正常工作

laravel-5 - 使用 Laravel 和 Vue 实现前端的最佳实践

javascript - 如何使整行可点击?

javascript - 如何改进 Lighthouse 报告 (PWA) 的 "Eliminate render-blocking resources"?