【问题标题】:css 960 grid clearfix not working but clear:both does workcss 960 网格 clearfix 不工作但很清楚:两者都有效
【发布时间】:2012-07-09 23:40:00
【问题描述】:

我正在使用网格 960 并且无法让 clearfix 工作,但是如果我在元素上使用 clear:both,那么我可以获得所需的效果。我更喜欢使用 clearfix,因为我发现它更可靠(通常)。

在下面的代码中,标题部分有一个左侧徽标区域和一个右侧横幅区域,然后在其下方应该是一个导航栏。

这个导航栏是我遇到困难的元素。如果我将style="clear:both;" 添加到nav 元素,它工作正常。但是,如果我在 header 元素中使用 clearfix,它就不起作用。

Here is the page that does not work (using clearfix)

Here is the page that works (using clear:both)

HTML

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Home Page</title>
    <link href="css/reset.css" rel="stylesheet" type="text/css" />
    <link href="css/960_12_col.css" rel="stylesheet" type="text/css" />
    <link href="css/site.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="container" class="container_12 ">


    <header class="clearfix grid_12">
        <div id="logoarea" class="grid_6 alpha">
            <div id="title">
                <h1>iContinuity Directory Services</h1>
            </div>
            <div id="logindisplay">
                    [ <a href="/Account/LogOn">Log On</a> ]
                    [ <a href="/Account/Register">Register</a> ]

            </div>
        </div><!-- end logoarea -->

        <div id="headerbanner" class="grid_6 omega">
            <p>this is the header banner area</p>
        </div>

        <nav class="">

            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/About">About</a></li>
            </ul>

            <form action="/Search/Search" class="navsearch" method="get">
                <input class="textbox" id="search" name="search" type="text" value="" />
                <input type="submit" value="Search" />
            </form>  
        </nav>

    </header>


    <section id="main" class="grid_8 ">

        <h2>Welcome to iContinuity Services</h2>
        <p>

        </p>

    </section>



    <aside id="sidebar" class="grid_4">
        ontrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a lin
    </aside>


    <footer class="grid_12">
        <p>this is the footer area</p>
    </footer>

</div> <!-- end 960 grid container -->

</body>
</html>

我希望我没有做任何明显的错误,但我看不到。

【问题讨论】:

  • 我一定遗漏了什么,因为 clearfix 只是在做 clear:both 反正。
  • no clearfix 增加的远不止这些。它模拟添加一个空的 div,但它也有针对旧浏览器和较少使用的浏览器的技巧

标签: css grid clearfix


【解决方案1】:

如果你在你的 NAV 元素之前放置一个空的 DIV 并且上面有一个 clearfix 类,那么它应该可以工作。

【讨论】:

  • 让我尝试一下,我会报告回来....是的,这确实有效,但是我想避免添加 html。 (cleafix 的整个想法就是避免这种情况)
猜你喜欢
  • 2015-06-10
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
  • 2013-12-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-12
相关资源
最近更新 更多