To add a profile and button to the offcanvas in Bootstrap 5, you can use the following HTML code:

<!-- Offcanvas trigger button -->
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasExample" aria-controls="offcanvasExample">
  Open Offcanvas
</button>

<!-- Offcanvas -->
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
  <div class="offcanvas-header">
    <h5 class="offcanvas-title" id="offcanvasExampleLabel">Profile</h5>
    <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  </div>
  <div class="offcanvas-body">
    <div class="d-flex flex-column align-items-center">
      <img src="https://via.placeholder.com/150" class="rounded-circle my-3" alt="Profile picture">
      <h6>John Doe</h6>
      <p>Web Developer</p>
    </div>
    <hr>
    <ul class="list-unstyled">
      <li><a href="#">Settings</a></li>
      <li><a href="#">Privacy</a></li>
      <li><a href="#">Help</a></li>
    </ul>
  </div>
</div>

In this code, we have added a button with the class btn btn-primary to trigger the offcanvas. The data-bs-toggle and data-bs-target attributes are used to specify the target offcanvas element.

Inside the offcanvas, we have added a header with the title "Profile" and a close button. The body of the offcanvas contains the profile information, including a profile picture, name, and job title. We have also added a horizontal line and a list of links for settings, privacy, and help.

Note that the offcanvas-end class is used to position the offcanvas on the right side of the screen. You can use offcanvas-start to position it on the left side.

This code can be customized to suit your specific needs, such as changing the profile picture, name, and job title, or adding more links to the list.

add profile and button to offcanvas bootstrap5 in html

原文地址: https://www.cveoy.top/t/topic/uRA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录