0

我必须在我的 div 中浮动元素,我使用了在互联网上找到的 clearfix,但它不能正常工作。

<div id="header" class="clear">
    <div class="header-left"> <a href="#" class="logo"></a> </div>

    <div class="header-right">
        <div class="quick-drop">
            <ul>
                <li class="quicklinks">Quicklinks
                    <img src="images/quicklink-icon.png" />
                </li>
                <li class="dropdown">Select from dropdown
                    <img src="images/dropdown-icon.png" />
                </li>
            </ul>
        </div>

        <div class="search-block">
            <input type="text" class="search" name="search" placeholder="Search for something here" />
        </div>
    </div>

    <div class="header-nav">it should be below but it is under</div>
</div>

CSS

.clear:before, .clear:after {
    content:"\0020";
    display: block;
    height: 0;
    overflow: hidden;
}
.clear:after {
    clear: both;
}
.header-left {
    float:left;
    margin:40px 0;
}
.header-right {
    float:right;
    margin:40px 0;
}
.logo {
    background:url('../images/logo.png') no-repeat;
    width:250px;
    height:50px;
    display:block;
}
.quick-drop {
    display:inline-block;
}
.quick-drop ul {
    margin:0;
    padding:0;
    margin:18px 0;
}
.quick-drop ul li {
    list-style-type:none;
    display:inline-block;
    height:19px;
    padding:3px;
    text-align:center;
    font-size:12pt;
}
ul .quicklinks {
    color:#c7c7c7;
    border-right:1px #c7c7c7 solid;
}
ul .dropdown {
    color:#58159b;
}
.quick-drop ul li img {
    margin:0 15px;
}
.search-block {
    display:inline-block;
}
.search {
    background:url('../images/search-icon.png') right no-repeat #fff;
    background-position:260px;
    width:260px;
    height:16px;
    border:none;
    outline-color:#58159b;
    padding:15px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    color:#c7c7c7;
}

http://jsfiddle.net/qKFAc

应该在.header-nav2个div之下,但它在它们之下,我做错了什么?

谢谢你。

4

3 回答 3

1

明确的修复应该在浮动元素之后,如下所示:

从父级中删除 clear 类。然后:

<!-- Floated -->
<div class="clear"></div>
<div class="header-nav">it should be below but it is under</div>
于 2013-11-18T18:02:27.943 回答
1
.header-nav
{
    clear:left;
}

请添加此 CSS 规则

于 2013-11-18T18:16:10.730 回答
-1

添加这个:

.clear {
    clear: both;
}

jsFiddle:http: //jsfiddle.net/qKFAc/1/

于 2013-11-18T17:51:25.073 回答