Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
699 views
in Technique[技术] by (71.8m points)

html - Moving DOM elements below a fixed navigation bar

I have a fixed navigation bar, however, any time I try to create content after it, the content clips the navigation.

I could fix this by using relative positioning on the content, but I would really prefer NOT to do that.

How can I push content below a fixed navigation bar without resorting to strange CSS tactics?

Example Navigation:

nav{
    position:fixed;
    top:0;
    width:100%;
    border:1px solid black;
}

Putting the content class may have been misleading, Essentially, I want DOM elements to flow after the nav bar without clipping it. For example, imagine the following HTML coming after the nav:

<section>foo</section>
<p>bar</p>
<h2>fubar</h2>
<div>blah blah blah </div>

I would like to see the section come after the nav bar, and then the p after the section and so forth.

Original Example Problem (Not Reflective of the problem): http://jsfiddle.net/wZHcv/

New Fiddle: http://jsfiddle.net/4MLVT/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can put nav inside a div , then set the height of the div by nav height. The advantage of this: easier and more meaningful,and In other places you can use other code without concerns..

<div class="nav-box">
    <nav>
        <ul>
            <li><a href="#">foo</a></li>
            <li><a href="#">bar</a></li>
        </ul>
    </nav>
</div>

EXAMPLE


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...