How can I position a div column-10 to the right and make it stay fixed in place

I'm having an issue trying to position a div on the right side without causing content to overlap with the navbar. I've attempted using `position:absolute top:0 right:0`, but it's not working as intended.

        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5878a8a919691978495a5d0cbd7cbd5">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" 
        integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<nav class="navbar sticky-top navbar-expand-lg navbar-light" style="background-color: #025;">
            <div class="container-fluid">
              <a class="navbar-brand text-white" href="{% url 'users:home' %}" style="font-size: 25px; font-weight:600;">
                <img src="{% static 'images/apple-icon.png' %}" class="d-inline-block align-text-center"
                  style="margin-left: 50px; height: 40px;">
                Digi Dash
              </a>
            </div>
              {% else %}
                <a class="nav-link" href="{% url 'users:login' %}"><button type="button" class="btn btn-outline-primary text-white" style="border-radius: 10px;">Log In</button></a>
                </div>
              {% endif %}
            </div>
          </nav> 
          #side nav-bar
          <div class="container-fluid h-100">
            <div class="row h-100">
                <div class="col-2" id="side-nav" style="position:fixed">
                    <h4><img src="{{ user.profile.profile_pic.url }}" alt=""
                            style="max-width: 150px; max-height:150px; border-radius: 50%;"> <br>
                          <span> Hi <strong
                            style="color: #B9C04C; cursor:default;"> {{ user.username }}</strong></span>
                        <p></p></h4>
      
                    <!-- Navigation links in sidebar-->
                    <a class="text-center side-link text-white" href="#"><iconify-icon icon="material-symbols:dashboard"></iconify-icon> DashBoard</a><br />
                    <br />
                    <a class="text-center side-link text-white" href="#">My Order</a><br />
                    <br />
                    <a class="text-center side-link text-white" href=""><iconify-icon icon="solar:moon-fog-bold"></iconify-icon> Dark Mode</a><br />
                    <br />
                    <a class="text-center side-link text-white" href="#">My Address</a><br />
                    <br />
                    <hr>

                </div>
                <div class="col-10" style="position:sticky; right:0;">
        <div class='col-sm-12' url-endpoint='{% url "users:api_data" %}'>
            <div class='col-sm-5' style="float: left;">
                <canvas id="myChart2" width="400" height="200"></canvas>
            </div>
            <div class='col-sm-5' style="float: left;">
                <canvas id="myChart" width="400" height="200"></canvas>
            </div>
            <div class='col-sm-5' style="float: left;">
                <canvas id="myChart3" width="400" height="200"></canvas>
            </div>
            </div>

The goal is to have both the main navbar and side navbar fixed, while positioning a specific element on the right side. I'd like this element to scroll independently like on YouTube. Here's an image for reference:

https://i.sstatic.net/4dC2l.png

Answer №1

For achieving this effect, you can implement the following code snippet:

{
   position:fixed;
   top:0;
   right:0;
   height:100vh;
}

The 'position: fixed' property will anchor the div to a specific spot on the page, ensuring it remains in place even when scrolling. By utilizing 'vh' for the height attribute, the container will dynamically adjust its size based on the viewport height.

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

Show a notification on the screen if the source of the iframe is blank

Is there a way to show a message "Please click on a match to get started" when no match link has been clicked? For example, when the iframe does not have an src attribute. My backend is built on Django. Below is the HTML code snippet: </form><b ...

Try implementing a body template when using the mailto function

Is there a way to customize an HTML template for the mailto() function body? For example, suppose I have the following link: echo "<a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97f2faf6fefbd7f0faf6fefbb ...

Converting XML hierarchy into a flat HTML table using XSLT

Looking for a way to transform hierarchical XML into an HTML table? Here's the challenge: <node text="a" value="1"> <node text="gga" value="5"> <node text="dh" value="9"> <node text="tyfg" value="4"> < ...

Using the <a> </a> tag for navigating within the code logic

Currently, I am utilizing the <a> tag for clicking and navigating, as shown in the code snippet below. I am looking to navigate this code using the C# tag in the page_prerender event, based on the selected id. Can anyone offer assistance with this? ...

Establishing space between table rows

I need to create a specific margin between two rows in a table. In my css code, I have the following snippet: background-color: #72c2dd; margin-top: 25px; The background-color is being applied correctly, but the margin-top property is not working as int ...

Refreshing Div Element with PHP AJAX POST请求

It's me again. I'm feeling really frustrated with this code, it's starting to get on my nerves. I don't mean to keep bothering you, but I finally figured out where the issue was in the code and now I just need a little help with the fin ...

JavaScript issue with confirm/redirect feature not functioning as expected

A demonstration of JavaScript is utilized for deleting an employee in this scenario... <script type="text/javascript"> function deleteEmployee(employee) { var confirmation = confirm('Are you sure?'); if(confirmation) { ...

Unable to get spacing correct on loading page

My attempt at creating a loading page using CSS and HTML has hit a roadblock. I'm trying to show a loading bar that ranges from 0% to 100%. Despite my use of justify-content: space-between, I can't seem to get it right. I've searched through ...

Is it possible to show one element while hiding others upon clicking using JavaScript?

Concept My idea is to create a website with a navigation menu where only one section is visible at a time. Each section would become visible upon clicking a specific button in the navigation bar. Challenge I attempted to achieve this using the following ...

Arrangement of SVGs within one another

I am working on achieving a layout with multiple SVG elements arranged in a specific way. This layout involves a top-level gray box containing several orange boxes, each of which holds red boxes. The width and height of the top-level SVG are known. https: ...

Troubleshooting a problem with CSS animations disappearing

I've been experimenting with CSS animations and I've run into a bit of a snag. I'm looking to create a div that fades in with a delay - meaning it won't be visible until the animation starts. Here's what I have so far: http://jsfi ...

Steps for altering the color of an element when it hovers over a different element

I'm curious if it's possible to achieve something similar using CSS and how can I do it? HTML: <h2 id="hi">Hello!!! :) </h2> <h3 id="bye">Bye!! :( </h3> CSS: #hi:hover { #bye { color: green; } } ...

Issue with sticky positioning not functioning properly with overlapping scrolling effect

When the user scrolls, I want to create an overlapping effect using the 'sticky' position and assign a new background color to each div (section). However, despite setting 'top' to 0 for the 'sticky' position, the divs still s ...

Create CSS styles that are responsive to different screen sizes and

What is the best approach to ensure that these styles are responsive on any mobile device? nav ul ul { display: none; } nav ul li:hover > ul { display: block; } nav ul { background: #0066cc; background: linear-gradient(top, #0066cc 0%, #bbbbbb 10 ...

Aligning text vertically to the top with material UI and the TextField component

Seeking guidance on adjusting vertical alignment of text in <TextField /> const styles = theme => ({ height: { height: '20rem', }, }); class Foo extends React.component { ... <TextField InputProps={{ classes: ...

Is it possible to maintain the maximum height and width of a div across all levels of zoom?

In the process of developing a web application, I encountered an issue regarding setting the width and height of a div to a fixed number, regardless of the zoom level. While I was successful in changing the background color of the div across all zoom level ...

Resizing images in HTML can sometimes lead to extra white space appearing underneath the

I am facing an unusual scaling issue with my website design. Whenever I resize the browser window horizontally, the image scales correctly, but it leaves a white space below it where the rest of the page should start from if the window is large. I'm ...

What is causing this iframe ads code to so severely disrupt the functionality of Internet Explorer when using document.write

So, I've recently encountered an issue where a certain problem arose, and although I managed to fix it, I am still curious about the root cause behind why it occurred in the first place. TL;DR The use of Google-provided conversion tracking code that ...

What is the best way to display a placeholder instead of the state's value when a page loads?

I'm having trouble displaying the placeholder of an input instead of its state value. When the page loads, it shows an empty select box because the testType state is null initially. How can I make sure that only the placeholder is shown instead of the ...

Ways to activate a function upon validation of an email input type

Within my HTML form, there is an input type="email" field that requires a valid email pattern for acceptance. I am attempting to send an AJAX request to the server to confirm whether the entered email already exists in the database after it has been verif ...