Bootstrap 5 sidebar problem

Cenk 1,021 Reputation points
2022-08-09T13:19:24.44+00:00

Hi,

I am working on a Blazor Server Application. I have this Radzen menu (NavMenu.razor);

<RadzenPanelMenu>  
    <RadzenPanelMenuItem Text="General" Icon="line_weight">  
        <RadzenPanelMenuItem Text="Home" Path="/" Icon="home"></RadzenPanelMenuItem>  
    </RadzenPanelMenuItem>  
    <RadzenPanelMenuItem Text="Orders" Icon="add_shopping_cart">  
        <RadzenPanelMenuItem Text="Orders List" Path="orders" Icon="receipt_long"></RadzenPanelMenuItem>  
        <RadzenPanelMenuItem Text="Orders Upload" Path="upload" Icon="file_upload"></RadzenPanelMenuItem>  
        <RadzenPanelMenuItem Text="Orders Export" Path="export" Icon="post_add"></RadzenPanelMenuItem>  
    </RadzenPanelMenuItem>  
    <RadzenPanelMenuItem Text="Vendors" Icon="face">  
        <RadzenPanelMenuItem Text="Vendor List" Path="vendors" Icon="account_box"></RadzenPanelMenuItem>  
    </RadzenPanelMenuItem>  
    <RadzenPanelMenuItem Text="Customers" Icon="paid">  
        <RadzenPanelMenuItem Text="Customer List" Path="customers" Icon="add_cart"></RadzenPanelMenuItem>  
    </RadzenPanelMenuItem>  
    <RadzenPanelMenuItem Text="Administration" Icon="paid">  
        <RadzenPanelMenuItem Text="User Management" Path="administration" Icon="security"></RadzenPanelMenuItem>  
    </RadzenPanelMenuItem>  
</RadzenPanelMenu>  

But I want to use https://getbootstrap.com/docs/5.0/examples/sidebars/# collapsible for the sidebar. I copied sidebars.css and the related HTML tags but there are some problems with the outcome.

229601-sidebar.png

Can you please help me?

I forgot to mention that clicking the menu items, triggers the toggler to hide and show. How can I only trigger the sidebar hide and show only with the toggler icon?

Thank you.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,624 questions
{count} votes

Accepted answer
  1. Ruikai Feng - MSFT 2,581 Reputation points Microsoft Vendor
    2022-08-16T02:59:14.7+00:00

    Hi,@ Cenk-1028
    I checked your codes and

    main {  
        display: flex;  
        flex-wrap: nowrap;  
        height: 100vh;  
        height: -webkit-fill-available;  
        max-height: 100vh;  
        overflow-x: auto;  
        overflow-y: hidden;  
    }  
    

    in your sidebar.css affected your former codes
    So I modified the codes and added class attribute to your main tag in sidebar page as below:

    .sidebarmain {  
        display: flex;  
        flex-wrap: nowrap;  
        height: 100vh;  
        height: -webkit-fill-available;  
        max-height: 100vh;  
        overflow-x: hidden;  
        overflow-y: hidden;  
    }  
    

    in your NavMenu.razor:

    ......  
    <main class="sidebarmain">  
    .......  
    

    then I added the codes in your MainLayout.razor:

    <style>  
    .pb-3,  
    .py-3 {  
      padding-bottom: 0.65rem !important;  
    }  
    </style>  
    

    231294-816-qa.png

    ----------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Best regards
    RuikaiFeng

    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Cenk 1,021 Reputation points
    2022-08-30T19:11:27.11+00:00

    @Ruikai Feng - MSFT I did some trial and error on the _Layout.cshtml. When I remove this <link href="IMS.WebApp.styles.css" rel="stylesheet"/> page structure is broken but menu worked correctly.

    236272-sidebar.png
    It was CSS isolation occurs at build time. Blazor rewrites CSS selectors to match markup rendered by the component. The rewritten CSS styles are bundled and produced as a static asset.

    Blazor CSS isolation

    Any idea how to fix it?

    0 comments No comments

  2. Cenk 1,021 Reputation points
    2022-09-01T15:21:22.087+00:00

    It works correctly on mobile portrait and landscape but still couldn't find out not working on others.

    237022-mobile.png

    0 comments No comments

  3. Hitesh Chauhan 1 Reputation point
    2022-11-16T06:27:09.343+00:00

    I understand the problem! Now the sidebar menu working correctly. find the Bootstrap 5 sidebar snippet. 260746-pure-css-fly-in-sidebar-nav.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.