html - 更改视频的高度并保持相同的宽度

标签 html twitter-bootstrap css

我有一个视频我想改变高度并保持相同的宽度例如全屏宽度我认为是 100% 和高度只是 200px 与这个网站 www.paypal.com 相同 问题是当我更改高度宽度时也会自动更改,视频会转到中心(水平拉伸(stretch))

        <video autoplay class="embed-responsive-item">
          <source src=test.mp4 type=video/mp4>
        </video>

视频{宽度:100%;高度:200px;

提前感谢任何帮助

最佳答案

PayPal 网站使用 CSS 属性 object-fit: cover以适应相同宽度的视频。

The object-fit CSS property specifies how the contents of a replaced element should be fitted to the box established by its used height and width.

https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit

.hero-home video {
    display: block;
    height: 100%;
    width: 100%;
    top: 0px;
    position: absolute;
    left: 0px;
    z-index: -1;
    object-fit: cover; /* this makes it fit within the video container */
    opacity: 0.9;
    transition: opacity 0.3s ease 0s;
}

object-fit 的可能值

/* Keyword values */
object-fit: fill;
object-fit: contain;
object-fit: cover;
object-fit: none;
object-fit: scale-down;

/* Global values */
object-fit: inherit;
object-fit: initial;
object-fit: unset;

他们还混合使用了 max-width , min-width , 和 min-height<video> 的一些父元素上元素。

只需检查 CSS,看看它们在做什么。您会看到视频的一部分被隐藏,而不是在 .video-container 上显示视频的所有高度。使用 overflow:hidden .

关于html - 更改视频的高度并保持相同的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34162910/

相关文章:

html - 导航栏中的 Twitter Bootstrap 搜索框在 chrome 和 firefox 中呈现不同

css - 将 li 元素排成一行

javascript - 多个 div 到一个 ajax 页面

PHP 和数据库

jquery - Bootstrap 按钮开关 - 添加另一个事件类

css - 无法将背景图像添加到 Bootstrap 模态

jquery - 撤消 CSS 级联行为

javascript - 一段时间后更改线性渐变背景

java - 自动在网页上移动

jquery - 是否可以自定义 jqgrid 的外观和感觉?