简体   繁体   English

CSS min-height: 100vh 为容器底部添加额外空间

[英]CSS min-height: 100vh add extra space to bottom of container

I am trying to use min-height: 100vh;我正在尝试使用min-height: 100vh; on my inner call to action div that sits on top of a background video.在我的内部号召性用语 div 上,它位于背景视频之上。 Everything works correctly, however, when I try to use 100vh with the absolutely positioned video it seems to add a block of margin to the section.一切正常,但是,当我尝试对绝对定位的视频使用100vh ,它似乎为该部分添加了一块边距。

How do I both use 100vh on the section and not have the extra margin?我如何在该部分同时使用100vh而没有额外的余量? I have tried calc, but that gets wonky with responsive and mobile devices.我试过 calc,但在响应式和移动设备上会变得不稳定。

CSS CSS

...
  .video-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;

    .video-background {
      object-fit: cover;
      object-position: center center;
      width: 100%;
      height: 100%;;
    }
  }

  .content-wrapper {
    @include media-breakpoint-up(xs) {
      display: flex;
      flex-direction: column;
      min-height: 100%;
      padding: 0;
      margin: 0;
    }
  }
...

.section-call-to-action {
  @include media-breakpoint-up(xs) {
    min-height: 100vh;
    padding: 0;
    margin: 0;

    .row {
      margin: 0;
      padding: 0;
    }
  }
...

HTML HTML

<div class="video-wrapper">
  <video autoplay="" class="video-background" loop="" muted="" playsinline="">
    <source src="..." type="video/mp4">
  </video>
</div>
<main class="container-fluid content-wrapper">
  <section class="container-fluid d-flex flex-column flex-fill justify-content-center section-call-to-action">

  </section>
  <section class="container-fluid d-flex flex-column section-venn-wrapper">

  </section>
  <section class="container-fluid section-robot-friends">

  </section>
</main>

在此处输入图片说明

UPDATE更新

  1. I have tried using min-height: calc(100vh - 5rem);我试过使用min-height: calc(100vh - 5rem); and that works in Chrome on a desktop but not Safari on iOS.这适用于台式机上的 Chrome,但不适用于 iOS 上的 Safari。
  2. I have come across this library https://github.com/Hiswe/vh-check but I am trying to address this with only CSS我遇到过这个库https://github.com/Hiswe/vh-check但我试图只用 CSS 来解决这个问题
  3. I tried to utilize iOS CSS but that is not working on iPads我尝试使用 iOS CSS 但这不适用于 iPad
  @supports (-webkit-overflow-scrolling: touch) {
    min-height: calc(100vh - 200px);
  }

If you come across this and know of a better solution, trust me I am all ears.如果您遇到此问题并知道更好的解决方案,请相信我,我全神贯注。

I setup js to detect if the viewer is ios...我设置了 js 来检测查看器是否是 ios ......

export default () => {
  const $sectionCallToAction = $('.section-call-to-action');
  const $iOS = navigator.userAgent.match(/Mac/) && navigator.maxTouchPoints && navigator.maxTouchPoints > 2;

    if ($iOS) {
    $sectionCallToAction.addClass('section-call-to-action-ios')
    }
};

Which appends this class...哪个附加了这个类......

.section-call-to-action-ios {
  min-height: 100vh !important;
  padding: 200px 0 0 0 !important;
  margin: -200px 0 0 0 !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM