html 对象适合 - 图像和视频的CSS背景大小封面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 对象适合 - 图像和视频的CSS背景大小封面相关的知识,希望对你有一定的参考价值。

/*** T H E - M A G I C - O F - O B J E C T - F I T ***/
/*****************************************************/

.video-container {
  height: 50vh;
  position: relative;
  overflow: hidden;
  @media(min-width: 600px) {
    height: 100vh;
  }
}

video {
  object-fit: cover; // Set the magic
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
}









/*** A E S T H E T I C S ***/
/***************************/

* {
  box-sizing: border-box;
}

body {
  background: #333;
  color: white;
}

.video-container:after {
  content: '';
  display: block;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(black, .2);
  z-index: 1;
}

h1 {
  text-transform: uppercase;
  font-weight: 900;
  margin: 0 0 1rem;
  padding: 0;
  line-height: 1;
  font-family: Futura, Helvetica, sans-serif;
  font-size: 5vw;
  @media (max-width: 400px) {
    font-size: 22px;
  }
  @media (min-width: 1200px) {
    font-size: 75px;
  }
}

.callout {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  height: 100%;
  text-align: center;
  position: relative;
  z-index: 10;
}

.support {
  position: fixed;
  bottom: 60px;
  right: 20px;
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 1px;
  text-align: right;
  position: relative;
  z-index: 10;
  a {
    color: white;
    text-decoration: none;
    position: relative;
    display: inline-block;
    margin-top: 10px;
    &:before {
      display: block;
      position: absolute;
      content: '';
      bottom: -2px;
      width: 0;
      height: 1px;
      background-color: rgba(white, .3);
      transition: .3s;
    }
    &:hover:before {
      width: 100%;
    }
  }
}




Object-Fit - CSS Background Size Cover for Images and Videos
------------------------------------------------------------
Object-fit cover for background videos. It's a new CSS property for sizing background videos like background images. IE and Edge not supported.

A [Pen](https://codepen.io/PixelCode95/pen/xrwNxp) by [Paolo Latoja](http://codepen.io/PixelCode95) on [CodePen](http://codepen.io/).

[License](https://codepen.io/PixelCode95/pen/xrwNxp/license).
<section class="video-container">
  <video src="https://player.vimeo.com/external/181445574.hd.mp4?s=d24f32d879305e931468d55e4d7ce6efb5a95c39&amp;profile_id=119" autoplay loop playsinline></video>
  <div class="callout">
    <h1>Object-Fit 

以上是关于html 对象适合 - 图像和视频的CSS背景大小封面的主要内容,如果未能解决你的问题,请参考以下文章

CSS背景图像适合div [重复]

CSS使图像调整大小并适合任何屏幕

裁剪背景图像,然后调整大小以适应特定尺寸 CSS/HTML

如何使背景图像跨越每个表格行并使用 HTML 和/或 CSS 动态调整大小?

调整大小以适合浏览器的背景视频

设置 div 背景图像以适合其大小?