Bootstrap側邊欄:創建一個具有交互性的導航菜單
導讀:前端開發前端開發Bootstrap是一款流行的前端框架,它提供了很多組件和工具,使得開發人員能夠更快速地構建現代化的網站和應用程序。其中之一就是側邊欄組件,它可以讓我們方便地為個業網站建設公司營銷型網站建設。
Bootstrap是一款流行的前端框架,它提供了很多組件和工具,使得開發人員能夠更快速地構建現代化的網站和應用程序。其中之一就是側邊欄組件,它可以讓我們方便地為網站添加導航菜單。
創建一個基本的側邊欄布局
首先,讓我們創建一個基本的側邊欄布局。我們需要在HTML頁面中添加以下代碼。
<div class="wrapper"> <!-- Sidebar --> <nav id="sidebar"> <div class="sidebar-header"> <h3>Bootstrap Sidebar</h3> </div> <ul class="list-unstyled components"> <li> <a href="#">Home</a> </li> <li> <a href="#">About</a> </li> <li> <a href="#pageSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">Pages</a> <ul class="collapse list-unstyled" id="pageSubmenu"> <li> <a href="#">Page 1</a> </li> <li> <a href="#">Page 2</a> </li> <li> <a href="#">Page 3</a> </li> </ul> </li> <li> <a href="#">Contact</a> </li> </ul> </nav> <!-- Page Content --> <div id="content"> <button type="button" id="sidebarCollapse" class="btn btn-info"> <i class="fas fa-align-left"></i> <span>Toggle Sidebar</span> </button> </div> </div>上面的代碼創建了一個包含側邊欄和主要內容區域的頁面布局。側邊欄中包含一個標題和一些導航鏈接,可以通過點擊“Pages”鏈接來展開子菜單。主要內容區域中包含一個按鈕,用于切換側邊欄的可見性。
添加樣式和交互功能
現在讓我們為側邊欄添加樣式和交互功能。我們需要在HTML頁面中添加以下樣式和腳本。
<style> .wrapper { display: flex; width: 100%; align-items: stretch; } #sidebar { min-width: 250px; max-width: 250px; background: #7386D5; color: #fff; transition: all 0.3s; } #sidebar.active { margin-left: -250px; } #sidebar .sidebar-header { padding: 20px; background: #6d7fcc; } #sidebar ul.components { padding: 20px 0; border-bottom: 1px solid #47748b; } #sidebar ul p { color: #fff; padding: 10px; } #sidebar ul li a { padding: 10px; font-size: 1.1em; display: block; } #sidebar ul li a:hover { color: #7386D5; background: #fff; } #sidebar ul li.企業網站建設active > a, a[aria-expanded="true"] { color: #fff; background: #6d7fcc; } a[data-toggle="collapse"] { position: relative; } a[aria-expanded="false"]::before, a[aria-expanded="true"]::before { content: '\e259'; display: block; position: absolute; right: 20px; font-family: 'Glyphicons Halflings'; font-size: 0.6em; } a[aria-expanded="true"]::before { content: '\e260'; } </style> <script> $(document).ready(function () { $("#sidebar").mCustomScrollbar({ theme: "minimal" }); $('#sidebarCollapse').on('click', function () { $('#sidebar').toggleClass('active'); $(this).toggleClass('active'); }); }); </script>聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-27 ,文章Bootstrap側邊欄:創建一個具有交互性的導航菜單主要講述側邊,菜單,前端開發網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_10502.html