這篇文章主要講解了“純css3開發(fā)的響應式設(shè)計動畫菜單詳細教程”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“純css3開發(fā)的響應式設(shè)計動畫菜單詳細教程”吧!
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),久治企業(yè)網(wǎng)站建設(shè),久治品牌網(wǎng)站建設(shè),網(wǎng)站定制,久治網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,久治網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
這是一個響應式設(shè)計的菜單。單擊列表圖標,當你顯示屏大小可以完全水平放下所有菜單項時,菜單水平顯示(如圖1)。當你的顯示屏不能水平放置所有菜單項時,菜單垂直顯示(如圖2)。 而且顯示的時候是以動畫的型式顯示。效果相當?shù)暮谩?/p>
圖1
圖2
下面是實現(xiàn)的代碼。
html代碼:
XML/HTML Code復制內(nèi)容到剪貼板
這里加入了兼容ie8的hack 。
css代碼:
CSS Code復制內(nèi)容到剪貼板
body
{
padding:0; margin:0;
}
.container
{
width:600px; margin:auto;
}
.iconicmenu {
position: relative;
height: 45px;
overflow: hidden;
}
.iconicmenu, .iconicmenu * {
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.iconicmenu input[type="checkbox"] { /* checkbox used to toggle menu state */
position: absolute;
left: 0;
top: 0;
opacity: 0;
}
.iconicmenu > label { /* Main label icon to toggle menu state */
z-index: 1000;
display: block;
position: absolute;
width: 40px;
height: 40px;
float: left;
top: 0;
left: 0;
background: white;
text-indent: -1000000px;
border: 6px solid black; /* border color */
border-width: 6px 0;
cursor: pointer;
-moz-transition: all 0.3s ease-in;
-webkit-transition: all 0.3s ease-in;
transition: all 0.3s ease-in; /* transition for flipping label */
}
.iconicmenu > label::after { /* inner stripes inside label */
content: "";
display: block;
position: absolute;
width: 100%;
height: 18%;
top: 19%;
left: 0;
border: 6px solid black; /* border color */
border-width: 6px 0;
-moz-transition: all 0.3s ease-in;
-webkit-transition: all 0.3s ease-in;
transition: all 0.3s ease-in; /* transition for flipping label */
}
.iconicmenu ul { /* UL menu inside container */
margin: 0;
padding: 0;
position: absolute;
margin-left: 40px;
background: #eee;
left: -100%; /* hide menu intially */
height: 40px; /* height of menu */
font: bold 14px Verdana;
text-align: center;
list-style: none;
opacity: 0;
-moz-border-radius: 0 5px 5px 0;
-webkit-border-radius: 0 5px 5px 0;
border-radius: 0 5px 5px 0;
-moz-perspective: 10000px;
perspective: 10000px;
-moz-transition: all 0.5s ease-in;
-webkit-transition: all 0.5s ease-in;
transition: all 0.5s ease-in; /* transition for animating UL in and out */
}
.iconicmenu li {
display: inline;
margin: 0;
padding: 0;
}
.iconicmenu ul label { /* label button inside UL to close menu */
cursor: pointer;
position: relative;
height: 100%;
text-align: center;
}
.iconicmenu ul label::after { /* label button x */
content: "x";
display: inline-block;
line-height: 14px;
color: white;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
width: 20px;
height: 20px;
background: black;
font-size: 18px;
margin: 5px;
margin-top: 10px;
-moz-transition: all 0.3s ease-in;
-webkit-transition: all 0.3s ease-in;
transition: all 0.3s ease-in;
}
.iconicmenu input[type="checkbox"]:checked ~ label, .iconicmenu ul label:hover::after {
-moz-transform: rotatey(180deg);
-ms-transform: rotatey(180deg);
-webkit-transform: rotatey(180deg);
transform: rotatey(180deg); /* flip labels vertically onMouseover */
}
.iconicmenu > label:hover, .iconicmenu > label:hover::after, .iconicmenu input[type="checkbox"]:checked ~ label, .iconicmenu input[type="checkbox"]:checked ~ label::after {
border-color: darkred; /* highlight color of main menu label onMouseover */
}
.iconicmenu input[type="checkbox"]:checked ~ ul {
left: 8px; /* Animate menu into view */
opacity: 1;
-moz-box-shadow: 1px 1px 5px gray;
-webkit-box-shadow: 1px 1px 5px gray;
box-shadow: 1px 1px 5px gray;
}
.iconicmenu li a {
display: block;
float: left;
text-align: center;
text-decoration: none;
color: black;
margin: 0;
padding: 10px;
padding-right: 15px;
height: 100%;
}
.iconicmenu li a:hover {
background: black;
color: white;
}
/* ----------------------------- CSS Media Queries ----------------------------- */
/*
These rules control which portions of the menu gets shown when the screen size is below a certain width.
By default 2 stages are defined depending on browser screen width.
*/
@media screen and (max-width: 580px) { /* Hide toggle icon when menu is already open (increases usable menu space by 40px) */
.iconicmenu input[type="checkbox"]:checked ~ label {
display: none;
}
.iconicmenu input[type="checkbox"]:checked ~ ul {
margin-left: 0;
}
}
@media screen and (max-width: 560px) { /* Convert horizontal menu to vertical drop down instead (friendly across all screen sizes) */
.iconicmenu {
overflow: visible;
}
.iconicmenu ul {
height: auto;
}
.iconicmenu ul li {
min-width: 200px;;
display: block;
}
.iconicmenu ul li a {
float: none;;
text-align: left;
}
}
感謝各位的閱讀,以上就是“純css3開發(fā)的響應式設(shè)計動畫菜單詳細教程”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對純css3開發(fā)的響應式設(shè)計動畫菜單詳細教程這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!