0

我想#text1在 的右侧显示#video1#text2在 的右侧显示#video2,但现在,#text2也在 的右侧显示#video1。那么有人可以解释为什么会发生这种情况吗?以及如何解决?

<style>
#video1, #video2
{
    float: left;
    margin: 20px 20px 0 0;
}
</style>
<div id="video1">
<iframe src="http://player.vimeo.com/video/65706935" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>
<div id="text1">
this is text1
</div>
<div id="video2">
<iframe src="http://player.vimeo.com/video/67739892" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>
<div id="text2">
this is text2
</div>
4

2 回答 2

0

你应该用“wrap” id 将你的部分包装成单独的 div 并在其中浮动你的#text #video Div:

<style>
    #text1, #text2 {
        float: right;
        margin: 20px 20px 0 0;
    }

    #video1, #video2 {
        float: left;
        width: 100px;
    }

    .wrap {
        width: 650px;
        float: left;
        border: 1px solid red;
        margin: 20px 20px 0 0;
    }
</style>

<div class="wrap">
    <div id="video1">
        <iframe src="http://player.vimeo.com/video/65706935" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
    </div>
    <div id="text1">
        this is text1
    </div>
    <div style="clear: both"></div>
</div>

<div class="wrap">
    <div id="video2">
        <iframe src="http://player.vimeo.com/video/67739892" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
    </div>
    <div id="text2">
        this is text2
    </div>
    <div style="clear: both"></div>
</div>
于 2013-07-23T03:43:51.947 回答
0

我编辑了你的代码,它工作正常。首先编辑您的html

<div id="video1">
    <span class="desc">this is text1</span>
    <iframe src="http://player.vimeo.com/video/65706935" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
    <div class="endfloat"></div>
</div> ....

CSS

.endfloat{ clear: both; margin: 0; padding: 0; }
#video1, #video2
{
   float: left;
   margin: 20px 10px 0 0;
} ....

检查这个小提琴的完整代码。希望这可以帮助。

于 2013-07-23T03:57:53.797 回答