简体   繁体   English

CSS浮动行为

[英]CSS floating behavior

I am making a div (red) that acts as a menu (screenshot 1), but when I add float:right; 我正在制作一个用作菜单的div (红色)(屏幕截图1),但是当我添加float:right; to the css the footer pops to the top on the page (screenshot 2) 到CSS的页脚弹出到页面顶部(屏幕截图2)


Screen Shot 1: 屏幕截图1: 屏幕截图1 Screen Shot 2: 屏幕截图2: 屏幕截图2


CSS: CSS:

.right-menu {
float:right;
width:10em;
height:35em;
background:red;/*temporary*/
padding:10px;
padding-top:20px;
padding-bottom:20px;
}

HTML: HTML:

<div class="right-menu">
    <form class="login">
        <input id="username" type="text" placeholder="User Name"/><br>
        <input id="password" type="password" placeholder="Password"/><br>
    </form>
    <form class="search">
        <input type="text" onkeyup="showResult(this.value)" placeholder="Search">
        <div id="livesearch"></div>
    </form>
    <a href="<? echo $siteAddress ?>download/password">Password</a><br>
    <a href="<? echo $siteAddress ?>support/contact">Contact</a><br>
    <a href="<? echo $siteAddress ?>support/help">Help</a><br>
    <a href="<? echo $siteAddress ?>legal/policy">Policy</a><br>
    <a href="<? echo $siteAddress ?>legal/terms">TOS</a><br>
    <a href="<? echo $siteAddress ?>support/adds">Adds</a><br>
</div>

Any idea whats happening? 知道发生了什么吗?

ps using firefox PS使用Firefox

Any idea whats happening? 知道发生了什么吗?

float means "Move to the side. Put any content after this element on the other side instead of below." float意思是“移到一侧。将任何内容放在此元素之后,而不是放在另一侧。”

Use the clear property to tell content not to move up beside a floated element. 使用clear属性告诉内容不要在浮动元素旁边向上移动。

#footer {
    clear: right; /* or both */
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM