Guide on creating a stationary side navigation bar in HTML with Bootstrap 5 and CSS

I am developing a website with a fixed side navigation bar that stays in place when scrolling through the content section. I experimented with both the fix-position in Bootstrap 5 and CSS methods, but no matter how I set it up, the side bar remains transparent in appearance and causes the content section to collapse and overlap with the side bar.

<body class="container-fluid row">
  <div class="navPart col-md-2 col-sm-2 d-none d-sm-block border">
    <nav class="navbar navbar-expand-lg navbar-light">
      <div class="container-fluid d-flex flex-column" style="height: 100vh;">
        <a class="navbar-brand d-none d-md-block" href="{% url 'seed_list' %} "><strong>projTree</strong></a>
        <div class="" id="navbarNav ">
          <ul class="navbar-nav d-flex flex-column">
            <li class="nav-item">
              <a class="nav-link active d-flex" aria-current="page" href="{% url 'seed_list' %} ">
                <img src="{% static 'seed/seed_list_icon.svg' %}" alt="alt">
                <p class="d-none d-md-block my-auto">Seeds</p>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="{% url 'posts' %} ">
                <img src="{% static 'seed/posts_icon.svg' %}" alt="">
                Posts
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">
                Pricing</a>
            </li>
            <li class="nav-item">
              <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
            </li>
          </ul>
        </div>
      </div>
    </nav>
  </div>
  <div class="contentPart col-md-8 col-sm-10 border">
    {% block content %}
    {% endblock %}
  </div>
  <div class="infoPart col-md-2 col-sm-0 border">
    <div class="search">
      <form class="d-flex flex-column row g-2 mt-1" method="POST" action="{% url 'search_seed' %} "> {% csrf_token %}
        <input class="form-control" type="search" placeholder="Search" aria-label="Search" name="searched">
        <button class="btn btn-outline-secondary" type="submit">Search</button>
      </form>
    </div>
    <div class="message">
      {% if messages %}
      {% for message in messages %}
      <div class="alert">
        {{message}}
      </div>
      {% endfor %}
      {% endif %}
    </div>
  </div>

The HTML code above showcases my efforts. I aspire for my layout to resemble that of the Duolingo website, where the side bar remains fixed and does not shift when scrolling.

Answer №1

Figured it out! The key is to ensure that the position-fixed class tag is placed one level below the top nav div. If it is placed at the same level, it may interfere with other content on the page. Essentially, fix the content within the nav segment, rather than the nav segment itself.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

unable to access various attributes in an angular directive

I have a particular HTML setup that effectively outlines each attribute's value through a distinct "attachment" directive. These values are located in the attrs list of said directive, which is within a modal file upload form. <p>For Testing Pu ...

Crafting interactive image checkboxes

At present, the checkboxes in my application are quite basic with labels. However, our app designer has requested that we revamp this feature and make it more appealing by using clickable images that still function like checkboxes. Allow me to provide an ...

Is there a way to stack multiple divs on top of each other in my HTML login page?

Below is the HTML code for my form: <div style="display:block; margin:0 auto;"> <h2>Welcome</h2> </div> <div id="box"> <div id="box2"> <p id="pid"><b>Em ...

Add a new row to the table when a dropdown option is selected, and remove the row when deleted. Ensure that the row is only added

Here is my specific requirement: I need a table with a default row containing a dropdown menu in the first column. When an option is selected from the dropdown, a new table row should be added with the same content as the main row and a delete button for ...

Tips for sending a value or props to a CSS file

Is there a way to dynamically update the x and y position based on user clicks, and then apply these changes to the top and left properties of a div? .dataCardAbsolute { position: absolute; top: 100px; left: 300px; overflow: auto; } React.useEffec ...

Tips on toggling between slides with Bootstrap Carousel

I am in the process of designing a portfolio website and have encountered a challenge. I want to divide it into two sections - a brief introduction and a carousel for showcasing projects. While I have managed to set up both sections, I'm facing an iss ...

Locating the CSS pixel value without being affected by the browser's zoom settings

Check out this JS fiddle I created to illustrate my issue. As you zoom in and out of the browser page, the value of max-width that appears in the console keeps changing. However, in the CSS code it is always set to 500px. How can I retrieve the original CS ...

Modifying text size using JavaScript string manipulation

I'm currently experimenting with a countdown script, but I'm struggling to change the size of the numbers displayed. Can anyone help me find where I can adjust the font and font size in this script? var eventdate = new Date("February 20, 2014 11 ...

Ways to conceal a personalized context menu for right-click operations

I came across a helpful page (How to add a custom right-click menu to a webpage?) discussing "How to add a custom right-click menu to a webpage" The source does not provide any functionality to hide the menu. Any suggestions on how I can hide the menu? ...

Validation of Coldfusion Forms: File Input

What is the best way to determine in ColdFusion if a user has selected a file for upload to the server? Using IsDefined function doesn't provide that information. ...

Tips for formatting HTML to showcase two data cards when printing a page

My XML data input document can be neatly transformed into printable data cards, whether it's 2 to a page, 4 to a page, 9 to a page, or any other configuration. What is the most effective method for styling the data to fit the printing layout? How can ...

Different strategies for displaying a singular pie chart on multiple pages

I have implemented a pie chart on an HTML page and now I want to display this chart on multiple other HTML pages. Below is the JavaScript code for creating the pie chart: function piechart() { var chart; var legend; ...

How can I add navigation dots to my slider?

I've been experimenting with my slider and I managed to make it slide automatically. However, the issue is that there is no option to manually navigate through the slides. I am looking to add navigation dots at the bottom so users can easily switch be ...

Using absolute elements within a div that is positioned relative in HTML code

In the layout below: <div style="margin-top:0%" class="postcell"> <div id="postspantitle" > <span class="texts"><?php echo __('Başlık :', 'goldmem');?></span> </div> & ...

Changing the color of an Angular <div> element with scripting

I am currently working on an Angular 6 project and I need to change the colors of a div tag from a script after a click function. However, I also need to change it back to transparent. When I click on the "Inheritance" option, the background color of the ...

How can I ensure that my content stays fixed at the bottom of a scrolling div in Material UI React?

I have developed a React JS component using Material UI that includes a chat input feature. However, I am facing an issue where the width of the chat input is always half the screen size on desktop or mobile devices. When I try to change the width to 100%, ...

Ensuring various conditions with ngIf

I've created a toggle function that updates the text of a link, but I'm struggling to handle multiple conditions. For example, *ngIf="condition1 or condition2". Below is an excerpt from my code: <a routerLink="/ads" class="tip" (click)="togg ...

The collapse button in Bootstrap 3.3 and jQuery 1.1 appears to be visible but unresponsive when clicked

This code isn't functioning properly as it displays the three horizontal bar button, but nothing happens when clicked. bootstrap-3.3 jquery-1.1 Toggle navigation CopyHere <div class="collap ...

Focus on targeting dynamic IDs such as #event_rules_attributes_0_interval, #event_rules_attributes_1_interval, etc. using CSS3 styling

Styling input tags using their IDs can be very convenient due to the higher precedence weight they hold compared to classes. For instance, I set a default width for input.text elements within a specific container: .details .metadata input.text { width: 2 ...

What is the method for inserting form control values into a QueryString within HTML code?

Struggling with passing HTML form control values into a QueryString for page redirection. While I can easily input static values into a QueryString and retrieve them using PHP's GET method, I am encountering difficulties when it comes to dynamic valu ...