首頁 > web前端 > css教學 > 在 Bootstrap 中建立選項卡式藥丸和垂直藥丸導航選單

在 Bootstrap 中建立選項卡式藥丸和垂直藥丸導航選單

WBOY
發布: 2023-08-27 23:05:09
轉載
797 人瀏覽過

在 Bootstrap 中创建选项卡式药丸和垂直药丸导航菜单

Bootstrap provides several options for creating navigation menus, like tabbed and vertical pills. To create this kind of navigation menus in Bootstrap, we can use the built-in class and igation menus in Bootstrap, we can use the built-in class and framework. This aids in creating a stylish and functional navigation menu that works well on all devices.

方法 - 1:選項卡式導覽

In this type of menus each tab represents a different section of the website. The pills are arranged horizo​​ntally. Whenever a tab is clicked, the corresponding section gets displayed.

#Algorithm
  • 載入Bootstrap的CSS和JavaScript檔案。
  • Add a container element with the heading "Tutorialspoint".
  • #Create a navigation menu with 3 tabs.
  • #聲明每個選項卡。
  • 為每個選項卡添加一些內容。
  • Load the Bootstrap JavaScript and jQuery files.

Example

<!DOCTYPE html>
<html>
<head>
	<title>Tabbed Pill Navigation Menu Example</title>
	<!-- Add Bootstrap CSS -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
   <!-- Container for the navigation menu and content -->
	<div class="container mt-4">
		<!-- Page title -->
		<h1>Tutorialspoint</h1>
		<!-- Navigation menu with tabs as pills -->
		<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
			<!-- Home tab -->
			<li class="nav-item">
				<a class="nav-link active" id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Home</a>
			</li>
			<!-- Profile tab -->
			<li class="nav-item">
				<a class="nav-link" id="pills-profile-tab" data-toggle="pill" href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</a>
			</li>
			<!-- Contact tab -->
			<li class="nav-item">
				<a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</a>
			</li>
		</ul>
		<!-- Content for each tab -->
		<div class="tab-content" id="pills-tabContent">
			<!-- Home tab content -->
			<div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
				<h1>Home</h1>
				<p>Lorem ipsum dolor sit amet.</p>
			</div>
			<!-- Profile tab content -->
			<div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
				<h1>Profile</h1>
				<p>Lorem ipsum dolor sit amet.</p>
			</div>
			<!-- Contact tab content -->
			<div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">
				<h1>Contact</h1>
				<p>Lorem ipsum dolor sit amet.</p>
			</div>
		</div>
	</div>
	<!-- Add Bootstrap JS -->
   <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
   <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
登入後複製

方法 - 2:垂直藥丸導航

垂直標籤頁,另一方面,是一種導航選單類型,其中連結垂直排列而不是水平排列。這有助於創建流暢的用戶體驗。

Algorithm
  • 建立一個帶有標題「Tutorialspoint」的容器。
  • The container should have one row and two columns.
  • #第一列包含垂直導覽選單,而第二列則顯示所選選單項目的內容。
  • 選單是使用"nav"和"nav-pill"類別建立的,這使得選單項目以類似藥丸的垂直樣式顯示。
  • 每個項目都是一個帶有唯一「href」的錨點標籤,該標籤連結到顯示相應內容的「選項卡面板」。
  • The content of each menu is displayed in a "tab pane" wrapped in a "tab content" class.
  • #The JavaScript code includes the jQuery library and some Bootstrap JavaScript plugins to make the menu work.

Example

<!DOCTYPE html>
<html>
<head>
	<title>Vertical Pill Navigation Menu</title>
	<!-- Add Bootstrap CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

	<!-- Add jQuery -->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

	<!-- Add Popper.js -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

	<!-- Add Bootstrap JS -->
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

	<style>
		body {
			background-color: #f8f9fa;
		}
		/* Style for nav links */
		.nav-pills .nav-link {
			color: #fff;
			background-color: #61a4f0;
			border-radius: 0;
			margin: 5px 0;
			font-weight: bold;
			padding: 10px;
			border: none;
			transition: all 0.2s ease-in-out;
		}
		/* Style for active and hover nav links */
		.nav-pills .nav-link:hover,
		.nav-pills .nav-link.active {
			background-color: #007bff;
			color: #fff;
			box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
		}
		/* Remove focus outline from nav links */
		.nav-pills .nav-link:focus {
			box-shadow: none;
			outline: none;
		}
		/* Style for tab content */
		.tab-content {
			background-color: #fff;
			padding: 20px;
			border-radius: 0 4px 4px 4px;
			box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
		}
	</style>
</head>
<body>
	<div class="container">
		<h1>Tutorialspoint</h1>
		<div class="row">
			<div class="col-md-3">
				<!-- Vertical navigation pills -->
				<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
					<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</a>
					<a class="nav-link" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</a>
					<a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</a>
					<a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</a>
				</div>
			</div>
			<div class="col-md-9">
				<!-- Tab content -->
				<div class="tab-content" id="v-pills-tabContent">
					<!-- Home tab -->
					<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
						<h3>Home</h3>
						<p>Welcome to the home page!</p>
					</div>
					<!-- Profile tab -->
					<div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
						<h3>Profile</h3>
						<p>Lorem ipsum dolor.</p>
					</div>
					<!-- Messages tab -->
					<div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">
						<h3>Messages</h3>
						<p>Lorem ipsum dolor.</p>
					</div>
					<!-- Settings tab -->
					<div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">
						<h3>Settings</h3>
						<p>Lorem ipsum dolor.</p>
					</div>
				</div>
			</div>
		</div>
	</div>
   <!-- Add Bootstrap JS -->
   <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
   <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
登入後複製

結論

這些類型的選單可以提升網站的使用者介面和使用者體驗。

Some of the alternate ways of implementation includes,
  • 使用自訂的CSS和javascript函數建立一個自訂選單。
  • 除了Bootstrap之外,像Materialize和Bulma這樣的CSS框架提供類似的功能。
  • 我們也可以使用一些第三方函式庫,如jQuery UI、UIkit和Semantic UI來建立這種導覽選單。
###

以上是在 Bootstrap 中建立選項卡式藥丸和垂直藥丸導航選單的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:tutorialspoint.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板