如何创建:折叠侧面板
- الصفحة السابقة الجانب الجانبي المقلوب
- الصفحة السابقة الصفحة التالية
学习如何创建可折叠的侧面板菜单。
创建折叠的侧面板
第一步 - 添加 HTML:
<div id="mySidepanel" class="sidepanel"> <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a> <a href="#">About</a> <a href="#">Services</a> <a href="#">Clients</a> <a href="#">Contact</a> </div> <button class="openbtn" onclick="openNav()">☰ Toggle Sidepanel</button> <h2>Collapsed Sidepanel</h2> <p>Content...</p>
第二步 - 添加 CSS:
/* 侧面板菜单 */ .sidepanel { height: 250px; /* Specify a height */ width: 0; /* 0 width - change this with JavaScript */ position: fixed; /* Stay in place */ z-index: 1; /* البقاء في الأعلى */ top: 0; left: 0; background-color: #111; /* أسود */ overflow-x: hidden; /* تعطيل التدول الأفقي */ padding-top: 60px; /* وضع المحتوى على بعد 60px من الأعلى */ transition: 0.5s; /* تأثير التدرج 0.5 ثانية لسحب الرفateral */ } /* روابط الرفateral */ .sidepanel a { padding: 8px 8px 8px 32px; text-decoration: none; font-size: 25px; color: #818181; display: block; transition: 0.3s; } /* تغيير لون الروابط عند وضع الفأرة عليها */ .sidepanel a:hover { color: #f1f1f1; } /* تحديد موقع وأسلوب زر الإغلاق (الجزء العلوي الأيمن) */ .sidepanel .closebtn { position: absolute; top: 0; right: 25px; font-size: 36px; margin-left: 50px; } /* تحديد أسلوب الزر المستخدم لفتح الرفateral */ .openbtn { font-size: 20px; cursor: pointer; background-color: #111; color: white; padding: 10px 15px; border: none; } .openbtn:hover { background-color: #444; }
الخطوة الثالثة - إضافة JavaScript:
/* جعل عرض الرفateral 250px (إظهاره) */ function openNav() { document.getElementById("mySidepanel").style.width = "250px"; } /* جعل عرض الرفateral 0 (إخفاءه) */ function closeNav() { document.getElementById("mySidepanel").style.width = "0"; }
الصفحات ذات الصلة
دروس:قائمة التوجيه CSS
- الصفحة السابقة الجانب الجانبي المقلوب
- الصفحة السابقة الصفحة التالية