Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the layout.

CSHTML
<div class="min-vh-100 d-flex flex-column">

        <header>
            <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark border-bottom box-shadow">
                <div class="container">
                    <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">ASP.NET</a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                            aria-expanded="false" aria-label="Toggle navigation">
                        
                    </button>
                    <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                        <ul class="navbar-nav flex-grow-1">
                            <li class="nav-item">
                                <a class="btn btn-primary" asp-area="" asp-controller="Home" asp-action="Create">
                                    class="fas fa-plus">   Create
                                </a>
                            </li>
                            <li class="nav-item">
                                <form class="form-inline" asp-controller="Search" asp-action="Index">
                                    <input name="query" class="form-control mr-sm-2" type="text" placeholder="Search">
                                    <button class="btn btn-primary" type="submit">Search</button>
                                </form>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
        </header>

        <div class="flex-fill d-flex flex-column">
            <div class="container d-flex flex-column flex-fill">
                <div class="row flex-fill">
                    <div class="col-md-9 bg-light p-1">
                        <main role="main" class="pb-3">
                            @RenderBody()
                        </main>
                    </div>
                    <div class="col-md-3 bg-info p-1 align-content-center">
                        <!-- a bunch of data displayed in foreach -->
                    </div>
                </div>
            </div>
        </div>

        <footer class="border-top footer bg-dark text-light">
            <div class="container">
                © 2021 - ASP.NET - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
            </div>
        </footer>

    </div>


Website looks as it should. But I want to make 2nd (right column) fixed-top, so the displayed data will stick in the same place as user scrolls through website.

Solution to that is simple. Just place fixed-top here:

CSHTML
<div class="col-md-3 bg-info p-1 align-content-center fixed-top">
   <!-- a bunch of data displayed in foreach -->
</div>


And it should work. Except I'm here, which means it doesn't. Right column gets magically teleported to left top corner and it stays there all the time, covering most of left column, and basically being in the wrong place.

Any suggestions how to fix it?

What I have tried:

Not much because according to all laws of bootstrap it should make element stick to the top, Googling did not help, no one had this problem before.
Posted
Updated 29-Mar-21 23:00pm

1 solution

Be sure you understand the ramifications of fixed position in your project; you may need to add additional CSS.
Fixed Positioning - Learn web development | MDN[^]

I suspect you want "sticky" positioning instead:
Sticky Top - Position · Bootstrap v4.6[^]
Sticky Positioning - Learn web development | MDN[^]
 
Share this answer
 
Comments
Member 15047625 30-Mar-21 6:22am    
Oh it's beautiful. Bootstrap is pretty damn huge, you have to forgive me for not finding sticky classes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900