以下是 css3蓝色导航菜单特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>css3蓝色导航菜单</title>
<link rel="stylesheet" type="text/css" href="css/base.css" media="all" />
<script type="text/javascript" charset="UTF-8" src="js/prefixfree.min.js"></script>
<style type="text/css" media="screen">
body {background-color: #F6F8F8;}
a {color:black;}
a:hover {color: #3d61a2;text-decoration: none;}
.demo {margin-top:40px;min-height:300px;}
.page-menu-wrapper {width:960px;line-height:45px;
margin: 0 auto;
background-color: #446cb3;
}
.page-menu-wrapper ul li{list-style:none;}
.page-menu-wrapper > ul > li {
position: relative;
float: left;
border-left: 1px solid #3d61a2;
border-right: 1px solid #3d61a2;
margin-right: -1px;
}
.menu-function {
float: left;
}
.menu-share {
float: right;
}
.page-menu-wrapper > .menu-function > li:first-child {
border-left: none;
}
.page-menu-wrapper > .menu-share > li:last-child {
border-right: none;
}
.page-menu-wrapper a {
position: relative;
display: block;
padding: 0 15px;
transition: all .3s ease-out;
}
.page-menu-wrapper > ul > li:hover > a {
color: #3d61a2;
background-color: #fff;
}
.page-menu-wrapper > ul > li:hover .dropdown-menu {
display: block;
}
.dropdown-menu {
display: none;
position: absolute;
width: 260px;
font-size: 18px;
font-weight: bold;
text-align: left;
background-color: #fff;
}
.dropdown-menu.categories a {
color: #000;
}
.dropdown-menu.categories a:hover {
color: #5bc4be;
margin-left: 10px;
}
#search:target a[href="#search"] {
display: none;
}
#search:target ~ #search-hidden {
display: block;
}
#search-hidden {
display: none;
padding: 0 5px;
background-color: #fff;
}
#search-hidden input {
border: none;
line-height: 24px;
width: 180px;
}
#search-hidden a {
float: right;
padding: 0;
width: 20px;
height: 45px;
}
#search-hidden a:before {
content: "\7d";
left: 0;
color: #446cb3;
}
.menu-function > li > a,.menu-share > li > a {
padding-left: 40px;
}
.page-menu-wrapper a:before {
position: absolute;
left: 15px;
font-family: 'icomoon';
font-style: normal;
speak: none;
font-weight: normal;
font-smoothing: antialiased;
font-size: 18px;
vertical-align: middle;
}
.menu-function > li:nth-child(1) > a:before {
content: "\e048";
}
.menu-function > li:nth-child(2) > a:before {
content: "\3b";
}
.menu-function > li:nth-child(3) > a:before {
content: "\7d";
}
.menu-share > li:nth-child(1) > a:before {
content: "\e0a2";
}
.menu-share > li:nth-child(2) > a:before {
content: "\e05b";
}
/*follow*/
.dropdown-menu.follow {
width: 223px;
}
.dropdown-menu.follow a {
padding-left: 35px;
font-size: 14px;
}
.dropdown-menu.follow a:before {
left: 10px;
}
.dropdown-menu.follow li:nth-child(1) a:before {
content: "\e0a5";
}
.dropdown-menu.follow li:nth-child(2) a:before {
content: "\e0a2";
}
.dropdown-menu.follow li:nth-child(3) a:before {
content: "\e04c";
}
.dropdown-menu.follow li:nth-child(4) a:before {
content: "\e022";
}
.dropdown-menu.follow li:nth-child(5) a:before {
content: "\e03d";
}
.dropdown-menu.follow li:nth-child(1) a {
color: #ffaa31;
}
.dropdown-menu.follow li:nth-child(2) a {
color: #07beed;
}
.dropdown-menu.follow li:nth-child(3) a {
color: #314d91;
}
.dropdown-menu.follow li:nth-child(4) a {
color: #2d2d2d;
}
.dropdown-menu.follow li:nth-child(5) a {
color: #e84788;
}
.dropdown-menu.follow li:nth-child(1):hover {
background-color: #ffaa31;
}
.dropdown-menu.follow li:nth-child(2):hover {
background-color: #07beed;
}
.dropdown-menu.follow li:nth-child(3):hover {
background-color: #314d91;
}
.dropdown-menu.follow li:nth-child(4):hover {
background-color: #2d2d2d;
}
.dropdown-menu.follow li:nth-child(5):hover {
background-color: #e84788;
}
.dropdown-menu.follow li:hover a {
color: #fff;
margin-left: 10px;
}
.dropdown-menu.share {
width: 120px;
right:0;
}
.dropdown-menu.share a {
margin: 10px;
line-height: 26px;
font-size: 12px;
padding-left: 20px;
border: 1px solid #cbcbcb;
border-radius: 2px;
color: #4c4c4c;
background-color: #efefef;
}
.dropdown-menu.share a:hover {
background-color: #fff;
}
.dropdown-menu.share li a:before {
font-size: 12px;
left: 5px;
}
.dropdown-menu.share li:nth-child(1) a:before {
content: "\e04c";
color: #314d91;
}
.dropdown-menu.share li:nth-child(2) a:before {
content: "\e0a2";
color: #07beed;
}
.dropdown-menu.share li:nth-child(3) a:before {
content: "\e022";
color: #2d2d2d;
}
@font-face {
font-family: 'icomoon';
src:url('fonts/icomoon.eot');
src:url('fonts/icomoon.eot?#iefix') format('embedded-opentype'),
url('fonts/icomoon.svg#icomoon') format('svg'),
url('fonts/icomoon.woff') format('woff'),
url('fonts/icomoon.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
</style>
</head>
<body>
<div class="page">
<header id="header">
<hgroup class="white blank">
</hgroup>
</header>
<section class="demo">
<div class="page-menu-wrapper clearfix">
<ul class="menu-function">
<li>
<a href="" title="">CATEGORIES</a>
<ul class="dropdown-menu categories">
<li><a href="" title="">Design</a></li>
<li><a href="" title="">Freebies</a></li>
<li><a href="" title="">Tutorials</a></li>
<li><a href="" title="">Coding</a></li>
<li><a href="" title="">Inspiration</a></li>
<li><a href="" title="">WordPress</a></li>
<li><a href="" title="">Resources</a></li>
</ul>
</li>
<li><a href="" title="">SHOP</a></li>
<li id="search">
<a href="#search" title="">SEARCH</a>
</li>
<li id="search-hidden">
<input type="text" name="" id=""><a href="#search-hidden" title=""></a>
</li>
</ul>
<ul class="menu-share">
<li>
<a href="" title="">FOLLOW US</a>
<ul class="dropdown-menu follow">
<li><a href="" title="">RSS</a></li>
<li><a href="" title="">Twitter</a></li>
<li><a href="" title="">Facebook</a></li>
<li><a href="" title="">Google+</a></li>
<li><a href="" title="">Dribbble</a></li>
</ul>
</li>
<li>
<a href="" title="">SHARE</a>
<ul class="dropdown-menu share">
<li><a href="" title="">Facebook</a></li>
<li><a href="" title="">Twitter</a></li>
<li><a href="" title="">Google+</a></li>
</ul>
</li>
</ul>
</div>
</section>
</div>
</body>
</html>
JS代码(prefixfree.min.js):
/** * StyleFix 1.0.3 & PrefixFree 1.0.7 * @author Lea Verou * MIT license */
(function(){
function t(e,t){
return[].slice.call((t||document).querySelectorAll(e))}
if(!window.addEventListener)return;
var e=window.StyleFix={
link:function(t){
try{
if(t.rel!=="stylesheet"||t.hasAttribute("data-noprefix"))return}
catch(n){
return}
var r=t.href||t.getAttribute("data-href"),i=r.replace(/[^\/]+$/,""),s=t.parentNode,o=new XMLHttpRequest,u;
o.onreadystatechange=function(){
o.readyState===4&&u()}
;
u=function(){
var n=o.responseText;
if(n&&t.parentNode&&(!o.status||o.status<400||o.status>600)){
n=e.fix(n,!0,t);
if(i){
n=n.replace(/url\(\s*?((?:"|')?)(.+?)\1\s*?\)/gi,function(e,t,n){
return/^([a-z]{
3,10}
:|\/|#)/i.test(n)?e:'url("'+i+n+'")'}
);
var r=i.replace(/([\\\^\$*+[\]?{
}
.=!:(|)])/g,"\\$1");
n=n.replace(RegExp("\\b(behavior:\\s*?url\\('?\"?)"+r,"gi"),"$1")}
var u=document.createElement("style");
u.textContent=n;
u.media=t.media;
u.disabled=t.disabled;
u.setAttribute("data-href",t.getAttribute("href"));
s.insertBefore(u,t);
s.removeChild(t);
u.media=t.media}
}
;
try{
o.open("GET",r);
o.send(null)}
catch(n){
if(typeof XDomainRequest!="undefined"){
o=new XDomainRequest;
o.onerror=o.onprogress=function(){
}
;
o.onload=u;
o.open("GET",r);
o.send(null)}
}
t.setAttribute("data-inprogress","")}
,styleElement:function(t){
if(t.hasAttribute("data-noprefix"))return;
var n=t.disabled;
t.textContent=e.fix(t.textContent,!0,t);
t.disabled=n}
,styleAttribute:function(t){
var n=t.getAttribute("style");
n=e.fix(n,!1,t);
t.setAttribute("style",n)}
,process:function(){
t('link[rel="stylesheet"]:not([data-inprogress])').forEach(StyleFix.link);
t("style").forEach(StyleFix.styleElement);
t("[style]").forEach(StyleFix.styleAttribute)}
,register:function(t,n){
(e.fixers=e.fixers||[]).splice(n===undefined?e.fixers.length:n,0,t)}
,fix:function(t,n,r){
for(var i=0;
i<e.fixers.length;
i++)t=e.fixers[i](t,n,r)||t;
return t}
,camelCase:function(e){
return e.replace(/-([a-z])/g,function(e,t){
return t.toUpperCase()}
).replace("-","")}
,deCamelCase:function(e){
return e.replace(/[A-Z]/g,function(e){
return"-"+e.toLowerCase()}
)}
}
;
(function(){
setTimeout(function(){
t('link[rel="stylesheet"]').forEach(StyleFix.link)}
,10);
document.addEventListener("DOMContentLoaded",StyleFix.process,!1)}
)()}
)();
(function(e){
function t(e,t,r,i,s){
e=n[e];
if(e.length){
var o=RegExp(t+"("+e.join("|")+")"+r,"gi");
s=s.replace(o,i)}
return s}
if(!window.StyleFix||!window.getComputedStyle)return;
var n=window.PrefixFree={
prefixCSS:function(e,r,i){
var s=n.prefix;
n.functions.indexOf("linear-gradient")>-1&&(e=e.replace(/(\s|:|,)(repeating-)?linear-gradient\(\s*(-?\d*\.?\d*)deg/ig,function(e,t,n,r){
return t+(n||"")+"linear-gradient("+(90-r)+"deg"}
));
e=t("functions","(\\s|:|,)","\\s*\\(","$1"+s+"$2(",e);
e=t("keywords","(\\s|:)","(\\s|;
|\\}
|$)","$1"+s+"$2$3",e);
e=t("properties","(^|\\{
|\\s|;
)","\\s*:","$1"+s+"$2:",e);
if(n.properties.length){
var o=RegExp("\\b("+n.properties.join("|")+")(?!:)","gi");
e=t("valueProperties","\\b",":(.+?);
",function(e){
return e.replace(o,s+"$1")}
,e)}
if(r){
e=t("selectors","","\\b",n.prefixSelector,e);
e=t("atrules","@","\\b","@"+s+"$1",e)}
e=e.replace(RegExp("-"+s,"g"),"-");
e=e.replace(/-\*-(?=[a-z]+)/gi,n.prefix);
return e}
,property:function(e){
return(n.properties.indexOf(e)?n.prefix:"")+e}
,value:function(e,r){
e=t("functions","(^|\\s|,)","\\s*\\(","$1"+n.prefix+"$2(",e);
e=t("keywords","(^|\\s)","(\\s|$)","$1"+n.prefix+"$2$3",e);
return e}
,prefixSelector:function(e){
return e.replace(/^:{
1,2}
/,function(e){
return e+n.prefix}
)}
,prefixProperty:function(e,t){
var r=n.prefix+e;
return t?StyleFix.camelCase(r):r}
}
;
(function(){
var e={
}
,t=[],r={
}
,i=getComputedStyle(document.documentElement,null),s=document.createElement("div").style,o=function(n){
if(n.charAt(0)==="-"){
t.push(n);
var r=n.split("-"),i=r[1];
e[i]=++e[i]||1;
while(r.length>3){
r.pop();
var s=r.join("-");
u(s)&&t.indexOf(s)===-1&&t.push(s)}
}
}
,u=function(e){
return StyleFix.camelCase(e)in s}
;
if(i.length>0)for(var a=0;
a<i.length;
a++)o(i[a]);
else for(var f in i)o(StyleFix.deCamelCase(f));
var l={
uses:0}
;
for(var c in e){
var h=e[c];
l.uses<h&&(l={
prefix:c,uses:h}
)}
n.prefix="-"+l.prefix+"-";
n.Prefix=StyleFix.camelCase(n.prefix);
n.properties=[];
for(var a=0;
a<t.length;
a++){
var f=t[a];
if(f.indexOf(n.prefix)===0){
var p=f.slice(n.prefix.length);
u(p)||n.properties.push(p)}
}
n.Prefix=="Ms"&&!("transform"in s)&&!("MsTransform"in s)&&"msTransform"in s&&n.properties.push("transform","transform-origin");
n.properties.sort()}
)();
(function(){
function i(e,t){
r[t]="";
r[t]=e;
return!!r[t]}
var e={
"linear-gradient":{
property:"backgroundImage",params:"red,teal"}
,calc:{
property:"width",params:"1px + 5%"}
,element:{
property:"backgroundImage",params:"#foo"}
,"cross-fade":{
property:"backgroundImage",params:"url(a.png),url(b.png),50%"}
}
;
e["repeating-linear-gradient"]=e["repeating-radial-gradient"]=e["radial-gradient"]=e["linear-gradient"];
var t={
initial:"color","zoom-in":"cursor","zoom-out":"cursor",box:"display",flexbox:"display","inline-flexbox":"display",flex:"display","inline-flex":"display"}
;
n.functions=[];
n.keywords=[];
var r=document.createElement("div").style;
for(var s in e){
var o=e[s],u=o.property,a=s+"("+o.params+")";
!i(a,u)&&i(n.prefix+a,u)&&n.functions.push(s)}
for(var f in t){
var u=t[f];
!i(f,u)&&i(n.prefix+f,u)&&n.keywords.push(f)}
}
)();
(function(){
function s(e){
i.textContent=e+"{
}
";
return!!i.sheet.cssRules.length}
var t={
":read-only":null,":read-write":null,":any-link":null,"::selection":null}
,r={
keyframes:"name",viewport:null,document:'regexp(".")'}
;
n.selectors=[];
n.atrules=[];
var i=e.appendChild(document.createElement("style"));
for(var o in t){
var u=o+(t[o]?"("+t[o]+")":"");
!s(u)&&s(n.prefixSelector(u))&&n.selectors.push(o)}
for(var a in r){
var u=a+" "+(r[a]||"");
!s("@"+u)&&s("@"+n.prefix+u)&&n.atrules.push(a)}
e.removeChild(i)}
)();
n.valueProperties=["transition","transition-property"];
e.className+=" "+n.prefix;
StyleFix.register(n.prefixCSS)}
)(document.documentElement);
CSS代码(base.css):
@charset "utf-8";@import url("http://www.w3cplus.com/download/reset.css");/* ------------------------------------------------- * common * -------------------------------------------------*/
.page{text-align:left;padding-top:40px;}
.wrap_top_nav{background-color:#333;box-shadow:0 1px 3px rgba(0,0,0,0.25),0 -1px 0 rgba(0,0,0,0.1) inset;height:40px;}
#top_nav{width:1000px;margin:0 auto;position:relative;}
#top_nav a{font-size:16px;line-height:40px;float:left;margin-right:20px;color:#999;text-decoration:none;}
#top_nav a:hover{color:#fff;}
#top_nav li:nth-child(1) a{background-image:url(http://www.w3cplus.com/sites/all/themes/marvin/logo.png);background-position:0 -12px;background-repeat:no-repeat;background-size:68px 60px;padding-left:74px;color:#fff;width:74px;overflow:hidden;}
#read{position:absolute;right:0;top:0;font-family:'����';}
#header{text-align:center;}
#header .white{color:#fff;}
#header .blank{color:#444;}
#header h1{font-size:24px;}
#header h2{font-weight:normal;}
#ad_w3cplus{width:750px;margin:100px auto;text-align:center;}
#ad_w3cplus .grid-ad{float:left;}