【问题标题】:Bootstrap 4 Not Obeying Height DirectivesBootstrap 4 不遵守高度指令
【发布时间】:2021-03-08 21:25:10
【问题描述】:

使用 Bootstrap 4 的 row 指令,我的 Web 布局中有 2 个元素应该分别占据可见屏幕高度的 25% 和 75%,但它似乎对元素的高度没有任何影响。

看起来电子邮件表单和图像视图只是包装元素内容所需的最小高度。我做错了什么?

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


<style>
.container {
  margin: 0;
  background: url(~@/assets/images/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: 40%;
  max-width: 40%;
}
</style>

【问题讨论】:

    标签: html css vue.js bootstrap-4 sass


    【解决方案1】:

    尝试在您的.container 中使用vh-100 而不是h-100,如果这不起作用,可以尝试添加:

      width: 100vw;
      height: 100vh;
    

    到你的.image-container 看看它是否修复它。

    【讨论】:

    • 在容器中使用vh-100 并没有改变任何东西,只是修改了你提到的css脚本实际上确实有效。这是为什么?似乎通过脚本而不是 html 操作视图更好,因为它更容易工作。
    • 我更喜欢亲自使用脚本。但是如果你想使用内联 html,我相信一个等价的答案也就是将 vh-100 vw-100 添加到你的 image-container 内联,所以它看起来像这样:&lt;div class="image-container row justify-content-center align-items-center vh-100 vw-100"&gt;
    猜你喜欢
    • 2015-03-04
    • 2016-01-21
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2014-07-20
    • 2018-09-13
    相关资源
    最近更新 更多