html5 底部固定菜单,CSS:如何实现顶部、底部的固定菜单

顶部固定菜单

#top-menu {

position: fixed;

z-index: 10;

left: 0;

right: 0;

top: 0;

background-color:rgba(255,255,0,0.5); /*透明效果*/

}

#top-menu li {

float: left;

list-style: none;

}

#top-menu a {

display: block;

padding: 5px 25px 7px 25px;

width: 4em;

text-align: center;

-webkit-transition: .5s all ease-out;

-moz-transition: .5s all ease-out;

transition: .5s all ease-out;

border-top: 3px solid white;

color: #aaa;

text-decoration: none;

}

#top-menu a:hover {

color: #000;

}

#top-menu li.active a {

border-top: 3px solid #333;

color: red;

}

#foo {

position: absolute;

top: 400px;

}

#bar {

position: absolute;

top: 800px;

}

#baz {

position: absolute;

top: 1200px;

}

Foo

Bar

Baz

主要实现在#top-menu。

效果:

4e22845495bec894aab7c7c414bff33d.gif

底部固定菜单

和上面的类似:

#top-menu {

position: fixed;

z-index: 10;

left: 0;

right: 0;

bottom: 0;

width: 100%;

background-color:rgba(255,255,0,0.5);

margin:0; /*很重要*/

}

#top-menu li {

float: left;

list-style: none;

}

#top-menu a {

display: block;

padding: 10px 25px 5px 25px;

width: 4em;

text-align: center;

-webkit-transition: .5s all ease-out;

-moz-transition: .5s all ease-out;

transition: .5s all ease-out;

border-bottom: 3px solid cyan;

color: #aaa;

text-decoration: none;

}

#top-menu a:hover {

color: #000;

}

#top-menu li.active a {

border-bottom: 3px solid #333;

color: red;

}

#foo {

margin-top: 400px;

}

#bar {

margin-top: 400px;

}

#baz {

margin-top: 400px;

}

Foo

Bar

Baz

效果:

2e8d6a11ce1cb18970eafc158c9204aa.gif

ul默认是有margin的,如果#top-menu不定义margin:0;,会变成:

6d477916b9c4942ce20d4702107102a2.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值