我試圖讓我的第一個移動第一站點,即使你點擊菜單,我的onclick也有輕微的問題。當你點擊菜單圖標並出現下拉菜單時,屏幕會顯示一點點,只顯示標題的一部分。你如何做到這一點,以便當你點擊菜單時,屏幕不會掉落或向下滾動。你可以在我的例子中我提出了我的意思,任何想法看,任何幫助是非常繼承人很欣賞我的演示鏈接:移動CSS導航點擊事件
演示:http://cssdeck.com/labs/jkxsecgl
這裏是我的HTML標記:
<body>
<div id="container">
<div id="header">
<h1>This is the header</h1>
<div class="main-nav" id="nav">
<a href="#nav" class="nav-open"> ☰ Menu</a>
<a href="#" class="nav-close"> ☰ Close</a>
<nav>
<ul>
<li><a href="#">home</a></li>
<li><a href="#">bio</a></li>
<li><a href="#">contact</a></li>
<li><a href="#">gallery</a></li>
</ul>
</nav>
</div>
</div>
<div id="content"><h1>This is the content</h1></div>
<aside><h1>The side bar</h1></aside>
<footer><h1>The Footer</h1></footer>
<div id="content"><h1>This is the content</h1></div>
<aside><h1>The side bar</h1></aside>
<footer><h1>The Footer</h1></footer>
</div>
</body>
CSS :
*{margin: 0px; padding: 0px;}
h1 {padding: 10px;}
#container {
position: relative;
width: 100%;
max-width: 320px;
background: rgba(51,0,255,.2);
margin: 0 auto;
}
#nav {
padding-left: 10px;
}
#nav nav ul, .nav-close, .nav-open {
list-style: none;
text-decoration: none;
}
.nav-close {
display: none;
}
#nav nav ul a {
text-decoration: none;
}
.nav-open, .nav-close {
background: yellow;
padding: 10px;
border: 1px solid;
}
#nav:target .nav-open {
display: none;
}
#nav:target .nav-close {
display: inline-block;
}
#nav nav {
position: relative;
text-align: left;
}
#nav nav ul {
position: absolute;
top: 0;
left: 0;
width: 100%;
max-height: 0;
max-width: 16em;
max-width: 16em;
background: #f6f6f6;
border-width: 0px;
border-style: dashed;
border-color: #aaa;
overflow: hidden;
-webkit-transition: max-height linear 0.5s;
-moz-transition: max-height linear 0.5s;
-ms-transition: max-height linear 0.5s;
-o-transition: max-height linear 0.5s;
transition: max-height linear 0.5s;
}
#nav nav ul li {
display: block;
background: orange;
border-bottom: 1px solid;
}
#nav nav ul li a {
padding: 0.3em 1.5em;
}
#nav:target nav ul {
max-height: 400px;
}
.nav-open {
display: inline-block;
}
#header {
width: 100%;
background: rgba(0,204,51,.7);
}
#content {
background: rgba(0,0,204,.6);
height: 300px;
}
aside {
background: rgba(153,0,0,0.9);
height: 300px;
}
footer {
width: 100%;
height: 150px;
background: rgba(102,255,255,1);
}
問題是,這是一個錨標記的默認動作,你可能可以用js覆蓋這個,但這可能違揹你在這裏嘗試做的。也只有css –
這是我正在使用的導航示例。他使用相同的默認標籤,但他點擊時不動,http://jeffri.me/2012/11/pure-css3-responsive-navigation-with-target/,注意如何當你點擊菜單,屏幕不會'噸下降。 –