html - 部分将导航栏移出屏幕

标签 html css

当我使用我的导航栏时,是否可以让它不被推出屏幕?

我试过将它们包装在单独的 div 中, overflow hidden 等。

理想情况下,它将位于带有 overflow:hidden 的静态页面上;但这只是我所拥有的一个快速模型。

注意这是一个 2 层导航,所以这个导航已经在另一个部分中了。

我有一个 JS fiddle here

HTML;

<html>
<head>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

li {
    float: left;
}

a {
    display: block;
    width: 60px;
    background-color: #dddddd;
}
section{
height:100vh;
}
</style>
</head>
<body>

<ul>
  <li><a href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a href="#about">About</a></li>
</ul>

<section id="home">
<p><b>Note:</b> If a !DOCTYPE is not specified, floating items can produce unexpected results.</p>
</section>

<section id="news">
<p>A background color is added to the links to show the link area. The whole link area is clickable, not just the text.</p>
</section>

<section id="contact">
<p><b>Note:</b> overflow:hidden is added to the ul element to prevent li elements from going outside of the list.</p>
<section>

</body>
</html>

最佳答案

您可以使用 position:fixed 并且您的导航栏始终位于顶部。

链接:https://jsfiddle.net/bz68252t/2/

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position:fixed
}
section:first-of-type{
padding-top:2em;
}

关于html - 部分将导航栏移出屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31969648/

相关文章:

php & MySQL - 允许用户更新他们的详细信息

html - 有没有比重复 ../更简单的 HTML 路径方法?

javascript - 使用 JS 切换页面颜色

javascript - 使用 javascript 的模态图像

javascript - Ajax 加载程序图像不工作

javascript - 如何使用 HTML5 和 CSS3 在一个圆圈中创建段

javascript - 在 Jquery 中隐藏汉堡菜单图标

html问题中的php变量

html - 如何将内容与文本框居中对齐?

C#/微软 SQL Server 2012 : Unicode symbols not displaying correctly (•)