CSS3制作Windows7開(kāi)始菜單
我對(duì)使用少量CSS3代碼來(lái)實(shí)現(xiàn)很多效果這一過(guò)程非常的著迷,很多UI元素都需要用圖片來(lái)展示其漂亮的外觀,但是你可能不知道,單純的CSS3代碼也是可以實(shí)現(xiàn)的。下面我就用純CSS3來(lái)制作Windows 7開(kāi)始菜單(額外需要幾個(gè)小圖標(biāo)),從而來(lái)證明這個(gè)觀點(diǎn)。
如果我們分解這個(gè)Windows 7開(kāi)始菜單,我們會(huì)得到1個(gè)div,2個(gè)ul列表,1組鏈接以及一些icon小圖標(biāo),我們可以一起來(lái)看看具體的效果。下面是簡(jiǎn)單的制作過(guò)程及部分代碼
菜單容器(Container)
這個(gè)容器命名為startmenu ,里面包含了2個(gè)ul列表。同時(shí)用3種顏色實(shí)現(xiàn)線性漸變:頂部是淺藍(lán)色,中間是深藍(lán)色,底部是接近淺藍(lán)色的其他顏色。接著用rgba()實(shí)現(xiàn)透明度,rgba()有四個(gè)參數(shù),前3個(gè)表示紅、綠、藍(lán),第4個(gè)表示透明度,兩條邊線使用了box-shadow屬性。
- #startmenu { border:solid 1px #102a3e; overflow:visible; display:inline-block; margin:60px 0 0 20px;
- -moz-border-radius:5px;-webkit-border-radius:5px; position:relative;
- box-shadow: inset 0 0 1px #fff; -moz-box-shadow: inset 0 0 1px #fff; -webkit-box-shadow: inset 0 0 1px #fff;
- background-color:#619bb9;
- background: -moz-linear-gradient(top, rgba(50, 123, 165, 0.75), rgba(46, 75, 90, 0.75) 50%, rgba(92, 176, 220, 0.75));
- background: -webkit-gradient(linear, center top, center bottom, from(#327aa4),color-stop(45%, #2e4b5a), to(#5cb0dc)); }
程序菜單(Programs Menu)
這是一個(gè)白色背景的ul列表,兩條邊線用了border和box-shadow屬性。程序鏈接包含了幾個(gè)小圖標(biāo)以及程序名稱,同時(shí)做了一個(gè)鼠標(biāo)滑過(guò)漸變投影的效果。
- #programs, #links {float:left; display:block; padding:0; list-style:none;}
- #programs { background:#fff; border:solid 1px #365167; margin:7px 0 7px 7px;
- box-shadow: 0 0 1px #fff; -moz-box-shadow: 0 0 1px #fff; -webkit-box-shadow: 0 0 1px #fff;
- -moz-border-radius:3px;-webkit-border-radius:3px;}
- #programs a { border:solid 1px transparent; display:block; padding:3px; margin:3px;
- color:#4b4b4b; text-decoration:none; min-width:220px;}
- #programs a:hover {border:solid 1px #7da2ce;
- -moz-border-radius:3px; -webkit-border-radius:3px;
- box-shadow: inset 0 0 1px #fff; -moz-box-shadow: inset 0 0 1px #fff; -webkit-box-shadow: inset 0 0 1px #fff;
- background-color:#cfe3fd;
- background: -moz-linear-gradient(top, #dcebfd, #c2dcfd);
- background: -webkit-gradient(linear, center top, center bottom, from(#dcebfd), to(#c2dcfd));}
- #programs a img {border:0; vertical-align:middle; margin:0 5px 0 0;}
鏈接菜單(Link Menu)
上面提到的鏈接菜單非常簡(jiǎn)單,但是這里我們可以做出更炫的鼠標(biāo)滑過(guò)效果。每一個(gè)鏈接菜單都有3種顏色的水平漸變:左邊和右邊是深藍(lán)色,中間用稍微淡一點(diǎn)的藍(lán)色?,F(xiàn)在,不像程序菜單中的鏈接那樣,這個(gè)鏈接內(nèi)部用<span>來(lái)包含菜單的文字,同時(shí)span元素還擁有多種垂直線性漸變。
- #links {margin:7px; margin-top:-30px;}
- #links li.icon {text-align:center;}
- #links a {border:solid 1px transparent; display:block; margin:5px 0; position:relative;
- color:#fff; text-decoration:none; min-width:120px;}
- #links a:hover {border:solid 1px #000;
- -moz-border-radius:3px; -webkit-border-radius:3px;
- box-shadow: 0 0 1px #fff; -moz-box-shadow: inset 0 0 1px #fff; -webkit-box-shadow: inset 0 0 1px #fff;
- background-color:#658da0;
- background: -moz-linear-gradient(center left, rgba(81,115,132,0.55), rgba(121,163,184,0.55) 50%, rgba(81,115,132,0.55));
- background: -webkit-gradient(linear, 0% 100%, 100% 100%, from(#517384), color-stop(50%, #79a3b8), to(#517384));
- }
- #links a span { padding:5px; display:block; }
- #links a:hover span { background: -moz-linear-gradient(center top, transparent, transparent 49%, rgba(2,37,58,0.5) 50%, rgba(63,111,135,0.5));
- background: -webkit-gradient(linear, center top, center bottom, from(transparent), color-stop(49%, transparent),
- color-stop(50%, rgba(2,37,58,0.5)), to(rgba(63,111,135,0.5))); }
下面是效果截圖,你也可以去看在線示例和下載源碼
這個(gè)CSS3制作的Windows 7開(kāi)始菜單例子可以在Firefox 3.6+, Safari 和 Chrome瀏覽器中運(yùn)行,Opera和IE中的效果就不行了,也許我可以繼續(xù)優(yōu)化一下,歡迎大家提出建議和意見(jiàn)。