modal appear behind fixed navbar

前端 未结 5 2167
生来不讨喜
生来不讨喜 2021-02-19 03:50

so i have bootstrap based site with fixed navigation bar (that follow you around the page at the top) and when i want to show modal popup, it appear behind those navigation bar,

5条回答
  •  一向
    一向 (楼主)
    2021-02-19 04:15

    I ran into this today and came up with an alternate solution that doesn't involve modifying the CSS. If you are using MVC, you can use a section tag and render the modal in the layout (anywhere in the body). This causes the default modal behavior to work and no longer hides it behind the nav bar.

    On _layout.cshtml (inside the body tag):

    
        
    
        @RenderSection("modals", required: false)
    
    
    

    and in your view:

    @section modals{
        @Html.Partial("_MyModal")
    }
    

    Something similar would work in other languages and most importantly doesn't require modifying the CSS.

提交回复
热议问题