Bootstap, what is bootstrap the world's most popular framework for building responsive, mobile-first sites
Bootstrap home page changed with their major release v5.1.0
Now here we will know what are the major changes in bootstrap 5
To work with new Bootstrap 5 features we need to add related css and js file into the file
script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"> </script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"> |
New Logo
Now they changed the logo ass curl brases and added B inside these braces
New Offcanvas
One of the major feature of the bootstrap5 is Offcanvas
What is Offcanvas component - It is a sidebar component that can be toggled via javascript to appear from the left, right or bottom edge of the viewport
Now let's create simple Offcanvas example with bootstrap5
Create simple HTML file and add Bootstrap5 css and js files
Now add our example code which will show offcanvas when we tap on toogle button
let's see the complete code
html> <head> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous"> </head> <body> <div class="container min-vh-100 py-2"> <div class="row"> <div class="col"> <h2 class="font-weight-light">Bootstrap 5 Sidebar</h2> <p> This is a Bootstrap 5 off-canvas menu example! </p> <div class="d-flex justify-content-end form-check form-switch form-control-lg"> <input class="form-check-input" type="checkbox" id="toggleSidebar"> <label class="form-check-label ms-1" for="toggleSidebar">Toggle Offcanvas</label> </div> <div class="text-center"> <img src="https://icons.getbootstrap.com/assets/img/icons-hero.png" /> </div> <div class="offcanvas offcanvas-start bg-light" tabindex="-1" id="offcanvasExample"> <div class="offcanvas-header"> <h5 class="offcanvas-title">Offcanvas</h5> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button> </div> <div class="offcanvas-body"> <div> Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc. </div> <div class="dropdown mt-3"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown"> Menu </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </div> </div> </div> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"> </script> <script> var toggle = document.getElementById("toggleSidebar") var offcanvas_el = document.getElementById("offcanvasExample") var offcanvas = new bootstrap.Offcanvas(offcanvas_el, {backdrop: false}) toggle.addEventListener("change", function(){ toggle.checked ? offcanvas.show() : offcanvas.hide() }) // handle case when sidebar is closed internally using `X` offcanvas_el.addEventListener('hide.bs.offcanvas', function () { toggle.checked = false }) </script> </body> </html> |
New Accordian
Bootstrap5 has one more feature called Accordian. Previously it has .card accordian now they changed to new .accordian component. This new accordian still uses Javascript plugin with some custom css and HTML.
This Accordian includes bootstrap Icons as chevron icons indicating state and clickability.
This new accordian has properties
Flush
To remove default background color by add .accordion-flush
Always Open
To open accrodin item when other item opens we need to remove the data-bs-parent attribute from each item
Simple Bootstrap Accordian example from official website
<html> </head> <div class="accordion" id="accordionExample"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"> toggle.addEventListener("change", function(){ // handle case when sidebar is closed internally using `X` </script> |
RTL (Right to Left)
Finally bootstrap introduced RTL supprt
To Enable RTL we need to required two attributes
Then we need to add RTl suported CSS file
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.rtl.min.css" integrity="sha384-gXt9imSW0VcJVHezoNQsP+TNrjYXoGcrqBZJpry9zJt8PCQjobwmhMGaDHTASo9N" crossorigin="anonymous"> |
Simple new bootstrap 5 RTL example from official website
<!doctype html> <html lang="ar" dir="rtl"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.rtl.min.css" integrity="sha384-gXt9imSW0VcJVHezoNQsP+TNrjYXoGcrqBZJpry9zJt8PCQjobwmhMGaDHTASo9N" crossorigin="anonymous"> <title>RTL Support</title> </head> <body style="padding:30px;"> <h1>RTL Support</h1> <!-- Option 1: Bootstrap Bundle with Popper --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> </body> </html> |
API Utilities
Added new API utiles Bootstrap
From official website Utilities
Speaking of utilities, we’ve added a ton of new ones to our arsenal, including:
Check out the Migration guide and utilities documentation for more details.
|
Article Contributed By :
|
|
|
|
717 Views |