html - 如何让导航菜单落在页面上?

标签 html css

我想知道如何将我的菜单从页面顶部之外拖放到页面顶部。让我表明我的意思。所以现在我是这样的

<--页面顶部-->
<--菜单直接在顶部-->

所以,我想做的是这样的:

<--就在页面顶部之外启动导航菜单-->
<--页面顶部-->
<--下降到当前位置-->

所以我只是想让它从顶部之外掉落到页面中。我假设这是一个 css 动画,但我不确定该怎么做。请建议一种方法。

这是我的 CSS 样式表。

body {
    font: 12px sans-serif;
    background-color: #eee;
    margin:0;
    padding:0;
}
/* Everything for the navigation */
.nav
{
margin:0 auto;
position:relative;
background:rgba(0,0,0.5);
background-color:#555;
height:60px;
width:50%;
box-shadow:0 0 2px #000;
font-size:13px;
}
.nav ul li
{
list-style-type:none;
display:inline;
margin-top:22px;
margin-left:75px;
float:left;
}
.nav ul li a
{
text-decoration:none;
color:#999;
transition:all 0.3s ease-in-out;
}
.nav ul li a:hover
{
color:#fff;
cursor:pointer;
transition:all 0.3s ease-in-out;
}
.logo
{
float:left;
margin-top:15px;
margin-left:75px;
}`

如果需要,这里是我的 html 代码。

<html>
<head>
        <title>Zegita</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
        <!--Navigation bar-->
        <div class="nav">
        <!--Logo-->
        <div class="logo">
        <a href="./"><img src="img/thumb.jpg" height="30" width="35" style="border-radius:3px;"></img></a>
        </div>
        <!--End Logo-->
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">My Github</a></li>
                <li><a href="#">Contact info</a></li>
                <li><a href="#">Projects</a></li>
            </ul>
        </div>
        <!--ending the navigation bar-->

        <!--starting the content area-->

        <!--ending the content area-->
        <!--starting the footer area-->

        <!--ending the footer-->
</body>
</html>`

最佳答案

您可以很容易地做到这一点,方法是将文档上方的页眉设置为负边距,并使用 jQuery 和 .animate()

HTML

<div class="header"></div>

CSS

html,body{
   margin: 0;
   padding: 0;
}

.header{
   background: black;
   width: 100%;
   height: 40px;
   margin: -100% 0 0;
}

JS

$(".header").animate({"margin": 0}, 1000);

EXAMPLE 1

如果你想使用 CSS 动画,你可以这样做:

.header{
   background: black;
   width: 100%;
   height: 40px;
   -webkit-animation: animateHeader 1s ease forwards;
}

@-webkit-keyframes animateHeader {
   from { margin: -100% 0 0; }
   to { margin: 0; }
}

@-moz-keyframes animateHeader {
   from { margin: -100% 0 0; }
   to { margin: 0; }
}

@keyframes animateHeader {
  from { margin: -100% 0 0; }
  to { margin: 0; }
}

EXAMPLE 2

关于html - 如何让导航菜单落在页面上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27853607/

相关文章:

html - 带编号的 CSS 自定义列表样式类型

css - Bootstrap Modal 弹出窗口显示在 html/css 中单击后退按钮

javascript - 整体选择按钮

jquery - 滚动响应 Bootstrap 中的固定 header 损坏?

html - 检查设备是否可以悬停

jquery - 响应式全屏背景图像,将显示其所有内容

javascript - 在一个文件中下载 css 和 js(包)

javascript - 用js检测onHover(jquery或css)事件

javascript - ViewData编译错误: BC30203: Identifier expected

javascript - 尝试在两次迭代中提醒同一选择器的值,在第一次迭代中获得正确的值,在第二个迭代中获得错误的值。为什么?