【问题标题】:Responsive iframe video list centered horizontal and max-width响应式 iframe 视频列表居中水平和最大宽度
【发布时间】:2019-02-24 04:21:11
【问题描述】:

我已经阅读了大量关于响应式 iframe 集成的帖子,无论是在谷歌这里还是在其他地方,但没有任何东西能解决我的具体问题。我认输了,我需要帮助。

目标:
创建三个(或更多)具有最大宽度和最大高度 (400 x 225) 但可以响应地缩小到最大值以下的 youtube 视频的响应式水平方向居中对齐列表。

我在哪里:
我创建了一个响应式垂直方向列表,其中包含三个 youtube 视频,每个视频都在自己的响应式容器中;但是,我无法让 iframe 水平定向并在视频容器中居中,同时保持响应。

我尝试过的:
(浮动:左;浮动:右;显示:内联块;对齐:左;对齐:右;填充:边距:)等。我已将 CSS 插入 html 本身,并插入 CSS 包含文件并测试了它们的许多排列和组合,但均无济于事。尽管如此,我还是在谷歌上对此进行了研究,虽然我发现了类似的场景,但我还没有找到解决这种特殊变化的方法。

结果:
我可以制作一个非响应式水平居中的视频列表,按照它的外观布局,但拒绝响应式调整大小,或者我可以制作一个最大宽度的响应式视频列表,该列表可以根据正在查看的任何视口正确调整大小,然而,它顽固地左对齐和垂直定向。我似乎无法两全其美。

代码:::

来自 CSS 的包括:

.video{
    color: #927c5a;
    font-family: "Impact", Impact,charcoal, sans-serif;
    font-size: 19px;
    font-weight: normal;
    height: auto;
    width: 100%;
    text-align: center;
    margin-bottom: 10px;
    display: inline;
    float: left;
    border: 1px solid blue;
    }        
.videoWrapper {
    position: relative;
    padding-bottom: 205px;
    padding-top: 25px;
    height: 0;
    max-width: 400px;
    max-height: 225px;
    border: 1px solid red;
    }
.videoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 400px;
    max-height: 225px;
    border: 1px solid green;
    }        

来自 HTML 文件:

<div class="video">
  <div class="videoWrapper">
    <iframe  src="https://www.youtube.com/embed/o6l14SkYtaY?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></div>

 <div class="videoWrapper">
   <iframe  src="https://www.youtube.com/embed/o6l14SkYtaY?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></div>

 <div class="videoWrapper">
   <iframe  src="https://www.youtube.com/embed/o6l14SkYtaY?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></div>
 </div>

【问题讨论】:

    标签: html css video iframe responsive


    【解决方案1】:

    不确定这是不是你想要的......

    .video {
       width: 100vw;
       height: 100vh;
       display: flex;
       flex-direction: column;
       justify-content: center;
       align-items: center;
    }
    
    iframe {
       max-width: 400px;
       max-height: 225px;
       width: 100%;
       height: 100%;
    }
    

    并删除.videoWrapper 额外的div

    【讨论】:

    • 不完全,但更接近。今天早上早些时候,我用 margin: auto; 解决了响应式浮动,同时保持了它的最大尺寸问题。所有的事情。所以它现在唯一没有做的就是居中。我刚刚插入了您的 css sn-ps,但仍然无法将其置于中心位置。此外,在您的代码中,它仍然垂直堆叠,即使它是居中的。如果添加 max-height: 400px;和最大宽度:225px;到 .video { 选择器,它们水平对齐,这也是我今天早上发现的。感谢您的意见。
    • 你用这个@Chasen 拯救了我的夜晚 - 谢谢!
    猜你喜欢
    • 2016-04-30
    • 1970-01-01
    • 2014-09-25
    • 2012-09-09
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多