简体   繁体   English

将一个右浮动元素包装在另一个下方

[英]Wrap one right-floated element underneath another

I'm trying to put 2 divs beneath each other like this: 我试图像这样将2个div相互放置:

div 1
div 2

This is how far i've gotten in the HTML-file: 这是我在HTML文件中得到的结果:

<div width="100%" z-index:"1">
            <div id="username-full">

                <div id="username-form">
                    <input type="text" name="username" id="username-input" placeholder="Username" />
                </div>

                <div id="username-text">
                    <p>Username:</p>
                </div>
            </div>
        </div>


        <div width="100%" z-index:"1">

            <div id="passwd-full">

                <div id="passwd-form">
                    <input type="text" name="passwd" id="passwd-input" placeholder="passwd" />
                </div>

                <div id="passwd-text">
                    <p>Password:</p>
                </div>

            </div>

        </div>

And this is my CSS-file: 这是我的CSS文件:

#username-full{
    text-align:right;
    float:right;
    clear:right;
}
#username-text{
    float:right;
    margin-right:5px;
}
#username-form{
    float:right;
    margin-top:13px;
}

#passwd-full{
    text-align:right;
    float:right;

}
#passwd-text{
    float:right;
    margin-right:5px;
}
#passwd-form{
    float:right;
    margin-top:13px;
}

Fiddle 小提琴

As you see, i've tried using the z-index, i've tried to give the 2 divs a width of 100% and i tried using float. 如您所见,我尝试使用z-index,我尝试将2 div的宽度设置为100%,并尝试使用float。 Also, I've tried using positioning, but that also didn't work. 另外,我尝试使用定位,但这也没有用。 I'm out of guesses :(. 我没有猜测:(。

Greetings, Luuk 问候,卢克

Based on your code, try adding this line: 根据您的代码,尝试添加以下行:

#passwd-full{
    clear: both;
}

I'm guessing, but have a look at this: 我正在猜测,但请看一下:

#passwd-full {
    ...
    clear: right;
}

Demo 演示

If you want two divs 100% with each and one above the other, you should try: 如果您希望两个div彼此之间都大于100%,则应尝试:

<div id="One">My first content</div>
<div id="Two">My second content</div>

#One, #Two {width: 100%; clear: both;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当左浮动元素与右浮动元素碰撞时如何清除? - How to clear left-floated element when it collides with a right-floated element? 窗口大小调整时右上浮动的Div - Center Right-Floated Div on Window Resize 最简单的方法来居中一个元素并使另一个浮动到右边 - simplest way to center an element and have another one floated to the right 右侧浮动侧边栏,主要内容流动 - 如何? - Right-floated sidebar with main content flowed around - how? 如何避免在带有文本和右浮动标签的td中进行文本换行 - How to avoid text wrapping in a td with text and a right-floated label 当左浮动 slider label 显示两位数值时,防止右浮动 slider 进一步向右移动 - Preventing right-floated slider from moving further right when left-floated slider label displays double digit value 我在顶部和右浮动的 div 之间有一个巨大的差距。 是什么造成了这个巨大的差距? - I have a giant gap between the top and my right-floated div. What is causing this huge gap? 右浮动元素下降 - Right floated element dropping 避免在不增加容器高度的情况下进行右浮动DIV包装 - Avoid right-floated DIV wrapping without adding any height in container 浮动DIV,随着窗口宽度减小,右浮动div与左div重叠 - Floating DIVs, right-floated div overlaps left divs as window width decreases
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM