简体   繁体   English

导航栏下方的页面内容

[英]content of the page going under the floating nav bar

I have made a nav bar that is fixed using unordered list which li elements are floating left.At first the bar was taking the whole width of the page as needed,but when I added content of the page,it went under the nav bar because she was floating. 我制作了一个导航栏,该导航栏使用无序列表固定,li元素向左浮动。起初,导航栏根据需要采用页面的整个宽度,但是当我添加页面内容时,它进入了导航栏下方,因为她在漂浮。

 ul { list-style-type: none; margin: 0; padding: 0; background-color: #333; overflow: hidden; position: fixed; } li { float: left; } li { display: block; color: white; text-align: center; text-decoration: none; padding: 14px 16px; } 
 <ul> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> </ul> 

How do I make my page content begin after the nav bar and give the bar it´s old look?And is there better way to make these bars/headers? 如何使页面内容在导航栏之后开始并赋予其旧外观?是否有更好的方法制作这些栏/标题?

The bar should take up the whole width of the page: 条形图应占据页面的整个宽度: 条应占据页面的整个宽度

Add width: 100% to the ul if you want it to be 100%. 添加width: 100%如果您希望ul为width: 100% ,则向ul添加100%。 Also, you could try width: 100vw to be 100% of the viewport. 另外,您可以尝试width: 100vw为视口的100%。

For the content to not appear under the nav bar, use body { padding: HEIGHT-OF-MENU } . 要使内容不出现在导航栏下方,请使用body { padding: HEIGHT-OF-MENU }

 ul { list-style-type: none; margin: 0; padding: 0; background-color: #333; overflow: hidden; position: fixed; width: 100%; } li { float: left; } li { display: block; color: white; text-align: center; text-decoration: none; padding: 14px 16px; } 
 <ul> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> </ul> 

You either need to assign a fixed height to the nav, then add that height as a padding-top to body, or you can make body display: flex; height: 100vh; 您需要为导航指定一个固定的高度,然后将该高度作为padding-top到主体,或者可以使body display: flex; height: 100vh; display: flex; height: 100vh; , and put the rest of the page content in an element adjacent to the nav, and set it to flex-grow: 1 and overflow-y: scroll . ,然后将其余页面内容放在与导航相邻的元素中,并将其设置为flex-grow: 1overflow-y: scroll If you do that, you can remove position: fixed from the nav, set the li 's to display: inline-block and the nav will span the width of the page. 如果这样做,则可以从导航中删除position: fixed ,将li设置为display: inline-block ,导航将跨越页面的宽度。

 ul { list-style-type: none; margin: 0; padding: 0; background: rgba(0,0,0,0.5); overflow: hidden; } li { display: inline-block; color: white; text-align: center; text-decoration: none; padding: 14px 16px; } body { margin: 0; height: 100vh; display: flex; flex-direction: column; } section { flex: 1 0 0; overflow-y: scroll; } 
 <ul> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> <li> <a href=#link></a> </li> </ul> <section> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> content<br> </section> 

Add width: 100% to the ul to make it full width. 添加width: 100% ul width: 100% ,使其变为全角。

To not have the content hide under the navbar, put the whole contant into a wraping div and assign padding-top: 60px (or whatever value fits) to it. 要使内容不隐藏在导航栏下,请将整个内容放入包装的div并为其指定padding-top: 60px (或任何合适的值)。

See my snippet below for some additional details. 有关其他更多信息,请参见下面的代码段。

 html, body { margin: 0; } ul { list-style-type: none; margin: 0; padding: 0; background-color: #333; overflow: hidden; position: fixed; width: 100%; height: 50px; } li { float: left; } li { display: block; color: white; text-align: center; text-decoration: none; padding: 14px 16px; } li a { color: white; } li a:hover { color: red; } .wrapper { padding-top: 60px; } 
 <ul> <li> <a href=#link>1111</a> </li> <li> <a href=#link>2222</a> </li> <li> <a href=#link>3333</a> </li> <li> <a href=#link>4444</a> </li> </ul> <div class="wrapper"> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> <p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus.</p> <p>Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p> </div> 

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

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