Responsive column with a fixed top navigation bar using Bootstrap 4

I've been working on designing a layout that features a sidebar on the left side, a fixed top navigation bar on the right side, and my site content underneath. Here is what I have so far:

<div class="container-fluid">
        <div class="row no-gutter">

            <!-- left side -->
            <div class="col-md-4 sidebar" style="background-color: red;">
                <p>test</p>
            </div><!-- end left side -->

            <!-- right side -->
            <div class="col-md-8 offset-md-4">

                <!-- nav -->
                <div class="row no-gutter" style="background-color: blue">
                    <nav class="col-12 navbar fixed-top navbar-toggleable-md">
                        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
                            <span class="navbar-toggler-icon"></span>
                        </button>
                        <div class="collapse navbar-collapse" id="navbar">
                            <ul class="navbar-nav">
                                <li class="nav-item">
                                    <a class="nav-link" href="#">Home</a>
                                </li>
                            </ul>
                        </div>
                    </nav>
                </div><!-- end nav -->

                <!-- main content -->
                <div class="row no-gutter" style="background-color: green;">
                    <div class="col-12">
                       <p> main content </p>
                    </div>
                </div><!-- end main content -->

            </div><!-- end right side -->
        </div>
</div>

https://jsfiddle.net/0ka85tmn/1/

I am having trouble getting the navigation bar to display correctly within its column. I've experimented with the position attribute but haven't been successful. Can anyone offer assistance?

Answer №1

When you use position:fixed, the navbar is taken out of the normal document flow and becomes relative to the entire page, rather than its parent. To ensure proper positioning of the navbar...

.navbar {
    position: fixed;
    width: 100%;
    top: 0;
    left: 33.3333%;
    z-index: 1;
}

Additionally, there's no need to wrap it in a row and col-12.

Check out the demo here: http://www.codeply.com/go/5bPIH8Tbiw

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

Changing the position of the scroll bar in a side navigation bar using JS/jQuery

On my website, there is a side navigation bar with the following CSS style: .scroll-box { overflow: hidden; width: 128px; } .filler { height: 256px; overflow-y: auto; } .selector { background-color: #369; padding: 8px 4px; text-align: cent ...

Where could one possibly find the destination of the mysterious <circle>?

I want to implement a simple pulsating animation on a circle svg element. I attempted using a transform: scale(..,..) animation, but it seems to be shifting the entire circle within its container instead of just scaling the element itself. This is the cur ...

Tips for displaying the contents of a URL within a div element

Is there a way to load a new page into a <div></div> without opening a separate tab? I tried using an iframe, but that method is not recommended and it includes scroll bars. <div id="iframeLogin"><a href="first.php" target="_self"> ...

Adjusting CSS rules dynamically using JavaScript or jQuery

I am seeking a method to dynamically change the CSS rules of an imported stylesheet within my document. The external stylesheet contains various classes and div attributes, and I aim to modify one of these rules using JavaScript or jQuery. For example: . ...

Some div elements are not compatible with the jQuery hover function

Being from Germany, please bear with me as I navigate through my English :D I've been working on implementing a hover function in jQuery to change the background color of certain divs on my webpage. However, I've encountered an issue where not e ...

Is there a way to trigger an image flash by hovering over a button using the mouseover feature in AngularJS2?

When I hover over the 'click me' button, I want an image to appear on the webpage. When I stop hovering, the image should disappear using the mouseover option. This is what I attempted in my app.component.ts and my.component.ts files: Here is t ...

Is it possible to implement a loading animation that remains visible until the entire page has finished loading?

After deploying my website on netlify, I noticed that only the HTML content is displayed until the page finishes loading. Does anyone have advice on how to make the website visible only after it has fully loaded? I have created a custom loading animation, ...

Determining the widths of elements when floated in Opera 11.*

I'm currently facing an issue with the Opera 11.5 beta (although I suspect this applies to all Opera 11 versions) where a floated block-level element (an unordered list) is being assigned a random fixed width, causing the child elements to wrap - simi ...

Enhance your coding experience with code completion and autocomplete in Angular/Typescript using ATOM within

Is it possible to have Codecompletion / Autocomplete in Atom similar to Webstorm? Currently I am getting familiar with TypeScript and really enjoying it, but the lack of Codecompletion support for my HTML files in Atom is quite frustrating. Having this f ...

Having difficulty passing HTML contents via FormData Append

I am having an issue with passing HTML content to the backend using FormData.append. Whenever I try to pass HTML content, I encounter an Internal Server 500 error. However, when I only pass text, the data is successfully sent to the backend. Here is the c ...

Difficulty arising from a CSS positioning issue with a 'menu' element

Having a div named "NormalInventory" with 32 children, each measuring 85px x 85px except for one which is larger at 175px x 175px, positioned relatively and displayed inline-block creating a CSS "list". Due to the size discrepancy, there are gaps in betwee ...

Change the border color of a form field in a material design if the user interacts with the

Is there a way to change the border color of a material form field in Angular when it is touched, focused, or active? I attempted to modify the color by overriding material css-class and also tried creating my own css class, but neither method had any ef ...

Customizing Employee Profile Pages in Django

Having just started with Django and Python, I am currently working on creating an Employee Management System using the Django framework. So far, I have successfully created models and displayed them in the admin module. My next goal is to develop a user pr ...

Striking a balance between innovation and backward compatibility in the realm of Web Design/Development

Creating websites is my passion, and I enjoy optimizing them for various platforms, devices, and browsers. However, lately, I've been feeling frustrated. I'm tired of facing limitations in implementing my creative ideas due to outdated technolog ...

Achieving a fixed footer at the bottom with absolute positioning on a webpage

I'm facing an issue with positioning a footer on my webpage, which is made up of div sections that are absolutely positioned. The problem arises because using the bottom property fixes the footer to the bottom of the screen rather than the bottom of t ...

Jade Syntax Error when Attempting to Render HTML Table

When attempting to showcase a basic HTML table in a Jade template, I encountered the following error: Error: c:\2406Node\myapp\views\table.jade:7 5| table, th, td { 6| border: 1px solid black; > 7| } 8| ...

Unable to modify the 'src' attribute of an Iframe using JavaScript

I've been working on a project using coinhive, but I encountered some difficulties. My initial goal was to display a webpage in an iframe while coinhive mined (don't worry, I'm only using it for personal purposes and not for anything illega ...

Issue with pre-selected checkboxes: JavaScript

A function was created to automatically check the first value of a checkbox when a page is loaded: function defaultCheck(){ document.checkBoxForm.list[0].checked = true; var val=document.checkBoxForm.list[0].value; showtotal[0] = docum ...

Enhancing the appearance of a modal popup with some flair

I recently integrated a modal popup AJAX control into my website. Upon clicking a button, the popup correctly appears but I am encountering issues with its styling. Although I have added a new style to my site master Site.css stylesheet, it is not being ...

Eliminating Google Adsense from Blog Posts

In each of my posts, I manually insert one Adsense unit. Here is the code: <div id="toppostad" style="float: left"> Adsense code </div> Initially, I assigned an id to the div when placing the code with the intention of using display:none; to ...