Table of Contents
Method - 1: Tabbed Navigation
Algorithm
Example
Method - 2: Vertical Pill Navigation
in conclusion
Home Web Front-end CSS Tutorial Create tabbed pill and vertical pill navigation menus in Bootstrap

Create tabbed pill and vertical pill navigation menus in Bootstrap

Aug 27, 2023 pm 11:05 PM

在 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 classes and components offered by the framework. This aids in creating a stylish and functional navigation menu that works well on all devices.

Method - 1: Tabbed Navigation

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

Algorithm

  • Load Bootstrap’s CSS and JavaScript files.

  • Add a container element with the heading "Tutorialspoint".

  • Create a navigation menu with 3 tabs.

  • Declare each tab.

  • Add some content to each tab.

  • 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>
Copy after login

Method - 2: Vertical Pill Navigation

Vertical tabs, on the other hand, are a type of navigation menu where links are arranged vertically instead of horizontally. This helps create a smooth user experience.

Algorithm

  • Create a container with the title "Tutorialspoint".

  • The container should have one row and two columns.

  • The first column contains the vertical navigation menu, while the second column displays the content of the selected menu item.

  • Menus are created using the "nav" and "nav-pill" classes, which cause menu items to be displayed in a pill-like vertical style.

  • Each item is an anchor tag with a unique "href" that links to a "tab panel" that displays the corresponding content.

  • 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>
Copy after login

in conclusion

These types of menus can enhance the user interface and user experience of your website.

Some of the alternate ways of implementation includes,

  • Create a custom menu using custom CSS and javascript functions.

  • In addition to Bootstrap, CSS frameworks like Materialize and Bulma provide similar functionality.

  • We can also use some third-party libraries, such as jQuery UI, UIkit and Semantic UI to create this kind of navigation menu.

The above is the detailed content of Create tabbed pill and vertical pill navigation menus in Bootstrap. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

See all articles