Lesson 28: Offcanvas in Bootstrap 5

Offcanvas, or horizontal sliding menus, can be easily created in Bootstrap 5. Below is how to create a horizontal menu or Offcanvas using Bootstrap 5.

Offcanvas, or horizontal sliding menus, can be easily created in Bootstrap 5. Below is how to create a horizontal menu or Offcanvas using Bootstrap 5 .

 

What is Offcanvas?

Offcanvas is similar to modal (it's hidden by default and shows when activated), except it's often used as a navigation menu for the sidebar of the screen.

How to create a horizontal sliding menu for the sidebar in Bootstrap 5

The following sample code shows how to create a sidebar with a horizontal sliding menu:

Offcanvas

Heading

Some text lorem ipsum.

Some text lorem ipsum.

   

Detailed explanation:

This class .offcanvascreates a sidebar with a horizontal sliding menu.

The class .offcanvas-startdefines the position of the horizontal sliding menu, giving it a width of 400px.

Class .offcanvas-titleensures proper alignment and line height.

Next, add the content inside the class .offcanvas-body.

To open the sidebar sliding menu, you must use an element that points to the container ID .offcanvas(#demo in the example).

 

To open a sidebar offcanvaswith the element , you can point to #demothe same attribute hrefinstead of data-bs-target.

For example:

 Bootstrap Example 

Menu QuanTriMang.com

Technology.

Life.

Science.

 

Sidebar slides horizontally

Offcanvas is similar to modal, except that it's often used as a sidebar.

  

 

Offcanvas location

Used .offcanvas-start|end|top|bottomto determine the position of the horizontal scrolling menu: left, right, top, or bottom.

Sample code for Offcanvas location:

Right:

For example:

 Bootstrap Example 

Menu TipsMake.com.com

Technology.

Life.

Society.

 

Offcanvas on the right

  

Above:

For example:

 Bootstrap Example 

TipsMake.com

The latest technology news channel.

 

Off-canvas top

  

 

Below:

For example:

 Bootstrap Example 

TipsMake.com

The leading technology news channel.

 

Off-canvas bottom

  

The menu slides horizontally to fit the screen size.

You can also control when you want to hide or show the offcanvas menu on different screen widths, using the class .offcanvas-sm|md|lg|xl|xxl:

 

For example:

 Bootstrap Example 

Menu TipsMake.com.com

Technology

Life

Science

 

The menu slides horizontally to fit the screen size.

This example hides the horizontal sliding menu on screens wider than 991px. The offcanvas button is also hidden (d-lg-none).

Adjust the browser window size to see the result.

  

 

Dark background horizontal sliding menu

Use a class .text-bg-darkto create a horizontal sliding menu with a dark background.

Tip: The sample code has added a class .btn-close-whiteto .btn-closecreate a white close button to make it stand out against a dark background:

 

For example:

 Bootstrap Example 

Menu TipsMake.com.com

Technology

Download

Studying IT

 

Dark background sidebar menu

  

Above is everything you need to know about creating a horizontal sliding menu or Offcanvas in Bootstrap 5. Hopefully, this article is helpful to you.

Related posts
Other Program articles
  • Lesson 27: Scrollspy in Bootstrap 5

    scrollspy là hiệu ứng hiển thị từng nội dung khi cuộn chuột. và bạn có thể tạo scrollspy dễ dàng trong bootstrap 5.
  • Lesson 26: Toast in Bootstrap 5

    toast cũng là một thành phần thú vị, giống như thông báo trên web, ứng dụng. dưới đây là cách tạo toast trong bootstrap 5.
  • Lesson 25: Popovers in Bootstrap 5

    popover cũng là một thành phần quan trọng trên web, ứng dụng. dưới đây là cách tạo popover trong bootstrap 5.
  • Lesson 24: Tooltips in Bootstrap 5

    tooltip là một box pop-up nhỏ, hiện ra khi người dùng di chuyển con trỏ chuột qua một nhân tố trên giao diện. dưới đây là cách tạo tooltip trong bootstrap 5.
  • Lesson 23: Modals in Bootstrap 5

    modal trong bootstrap 5 là thành phần hiện cửa sổ popup ở phía trên trang hiện tại. dưới đây là cách tạo hộp thoại hay popup bằng bootstrap 5.
  • Lesson 22: Carousel in Bootstrap 5

    carousel trong bootstrap 5 là một plugin được dùng để duyệt các phần tử như slide, ảnh… dưới đây là cách dùng carousel trong bootstrap 5.
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup