0

I have to Vimeo videos, and I am trying to make them sit side by side and centered in the body whenever a computer is viewing them. Then whenever a small screen (like an iPhone) is viewing them, I want the right one to drop beneath the left one and fit the size of the body.

Here is what I have so far. HTML:

<div class="vimeo-wrapper">
    <div class="vimeo-video-1 vimeo-standard">
        <iframe src="//player.vimeo.com/video/" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen align="middle" seamless></iframe>
    </div>
    <div class="vimeo-video-2 vimeo-standard">
        <iframe src="//player.vimeo.com/video/" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen align="middle" seamless></iframe>
    </div>
</div>

CSS:

.vimeo-standard {
    width:500px;
    height:auto;
    position:relative;
    margin: 10px auto;
    float: left;
}
.vimeo-video-2 {
    margin-left: 15px;
}
.vimeo-wrapper {
    width: 100%;
    position: relative;
    margin: 0 auto;
}

@media (max-width:767px) {
    .vimeo-standard {
        position: relative;
        padding-bottom: 56.25%; /* 16/9 ratio */
        padding-top: 30px; /* IE6 workaround*/
        height: 0;
        overflow: hidden;
    }
    .vimeo-video-2 {
        margin-left: 0;
    }
    .vimeo-standard iframe, .vimeo-standard object, .vimeo-standard embed {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

@media (min-width:768px) and (max-width:1199px) {
    .vimeo-standard iframe {
        width: 352px;
        height: 198px;
    }
    .vimeo-standard {
        width: 352px;
    }
    .vimeo-video-2 {
        margin-left: 10px;
    }
}

I have created some responsive CSS for it, but I am having trouble getting to just right so that it is centered, responsive, and side-by-side when it is fullscreen.

What should I change the HTML and CSS to for it to do this?

4

1 回答 1

1

我已经编辑了你的css,它现在更少并且完全响应。我添加了一些额外的borders内容,以便您可以识别标记内每个 div 的边界,您可以删除它们。

将物品放在容器内的关键是给予position:relativemargin:0 auto

是的,每当您需要在容器内使用浮动对象时,您都需要使用该容器,clearfix以便容器可以重置其height属性

检查它在小提琴

 .vimeo-wrapper {
        max-width: 980px;
        position: relative;
        margin: 0 auto;
        border: 1px solid green;
    }

    .vimeo-standard {
        float: left;
        height: 300px;
        width: 47%;
        border: 1px solid #000;
        margin: 10px;
    }

    iframe {
        width: 100%;
        height: 100%;
    }


    @media (max-width:767px) {

        .vimeo-standard {
            float: none;
            width: 80%;
            margin: 0 auto;
            padding-bottom: 10px;
        }
    }

    .clearfix:before,
    .clearfix:after {
        content: " "; /* 1 */
        display: table; /* 2 */
    }

    .clearfix:after {
        clear: both;
    }
于 2014-07-06T18:08:31.767 回答