Moving DOM elements below a fixed navigation bar

前端 未结 2 1218
死守一世寂寞
死守一世寂寞 2020-12-22 06:17

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

2条回答
  •  既然无缘
    2020-12-22 07:06

    We should wrap the content after navigation in a div and set position:relative and top greater than the height of the navigation bar.

    HTML CODE:
    
    
    
    foo

    bar

    fubar

    blah blah blah
    CSS CODE: nav{ position:fixed; top:0; width:100%; border:1px solid black; } nav ul li{ display:inline; } nav ul li a{ text-decoration:none; color:black; font-size:20px; -webkit-transition:all .5s; padding:5px; } nav ul li a:hover{ background:black; color:white; } .content{ position:relative; top:60px; }

提交回复
热议问题