Lesson 19: How to use Collapse in Bootstrap 5

Collapse in Bootstrap 5 allows you to hide or show content on a page using several JavaScript classes and plugins. Heres what you need to know about Collapse in Bootstrap 5.

Collapse in Bootstrap 5 allows you to hide or show content on a page using several JavaScript classes and plugins. Here's what you need to know about Collapse in Bootstrap 5 .

 

Basic usage of Collapse in Bootstrap 5

Collapse is useful when you want to hide and show a large amount of content on a page. Basically, the code would look like this:

 Nội dung. 

For example:

 Bootstrap Example 

Simple content hide/show button

Click the button to hide or show the content.

  Kênh thông tin công nghệ nhanh nhất, các bài học lập trình online, tin tức game, cập nhật xu hướng giới trẻ. 

 

Detailed explanation:

The class .collapse indicates the collapsible element () . This is the content that will be shown or hidden with a single click of a button.

To control collapsible (show/hide) content, add the attribute data-bs-toggle="collapse" to the element or bar.Then, add data-bs-target="#id" to connect that button to the collapsible content().

Note: For the `data-bs-target` factor, you can use the `href` attribute instead of `data-bs-target` .

Collapsible Lorem ipsum dolor text. 

By default, collapsible content is hidden. However, you can add a class .showto display it by default:

 Lorem ipsum dolor text. 

For example:

 Bootstrap Example 

By default, the content is displayed in a collapsible format.

Add the `.show` class next to the `collapse` class to default to displaying the content.

Click the button to toggle between showing and hiding the content.

  QuanTriMang.com là kênh kiến thức công nghệ hàng đầu hiện nay. Cập nhật nhanh mọi bản tin game, đời sống, xã hội, xu hướng hót trên mạng và nhiều hơn thế nữa. 

 

Accordion

This is a collapsible menu design in a stacked format. Note that the `data-bs-parent` property is used to ensure that all collapsible elements within a specific parent element will close when one of the collapsible items is displayed.

Basic code:

  Collapsible Group Item #1  Lorem ipsum.  Collapsible Group Item #2  Lorem ipsum.  Collapsible Group Item #3  Lorem ipsum. 

For example:

 Bootstrap Example 

An example of an accordion in Bootstrap 5.

Note: The `data-bs-parent` property ensures that all collapsible elements within the parent item are closed when another collapsible item appears.

  Mục QuanTriMang.com #1  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.  Mục QuanTriMang.com #2  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.  Mục QuanTriMang.com #3  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 

Above is how to collapse and expand menus on websites and applications using Bootstrap 5's Collapse feature . This component is quite easy to use with two basic styles. Remember it to diversify your project designs!

Other Program articles
  • Lesson 18: Creating a Dropdown Menu in Bootstrap 5

    dropdown hay tạo menu xổ xuống trong bootstrap 5 là một tính năng thú vị bạn không nên bỏ qua. dưới đây là cách dùng dropdown trong bootstrap 5.
  • Lesson 16: List Groups in Bootstrap 5

    list group hay nhóm danh sách trong bootstrap 5 là một thành phần linh hoạt và mạnh mẽ để hiển thị một chuỗi thông tin.hãy cùng quantrimang.com tìm hiểu cách dùng list-group trong bootstrap 5 nhé!
  • Lesson 15: Pagination in Bootstrap 5

    phần bài học bootstrap cơ bản này sẽ thảo luận về tính năng phân trang hay pagination. bootstrap 5 xử lý danh sách không theo đúng thứ tự giống như rất nhiều các nhân tố khác trên giao diện.
  • Lesson 14: Spinner in Bootstrap 5

    spinner trong boostrap 5 là gì? cách dùng spinner trong boostrap 5 như thế nào? hãy cùng tipsmake.com tìm hiểu nhé!
  • Lesson 13: Progress Bars in Bootstrap 5

    trong bài viết này, quantrimang sẽ tiếp tục hướng dẫn bạn sử dụng bootstrap để tạo các thanh tiến trình - progress bar.
  • Lesson 12: Badges in Bootstrap 5

    badge trong bootstrap rất cần thiết khi phát triển web và ứng dụng. Ở bài này, hãy cùng tipsmake.com.com tìm hiểu cách dùng badge trong bootstrap như thế nào nhé!
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