Can a Bootstrap vertical column be made sticky without defining its position?

I'm attempting to replicate the effect of a sticky column positioned to the right of some text, similar to what is seen on the Bootstrap website.

Below is the code I've been working with:

<nav class="col-sm-4 col-md-4"  data-spy="affix"  data-offset-top="205">
    <div class="panel panel-default" >
        <div class="panel-heading"><h1>Table of Contents</h1></div>
        <section class="panel-body">
            <p>
                Nullam luctus nisi est, id blandit nunc tristique vel! 
            </p>
        </section>
    </div>
</nav>

(There's another bar on the left taking up the 8 previous columns)

Although it somewhat functions as intended - the sidebar appears in the correct place when the page loads and sticks to the top when scrolled up - there's an issue where it shifts to the left, overlaying the left-most column and expanding its width unexpectedly (to around 5 columns wide).

Upon reviewing the documentation, it seems that I need to manually configure the .affix class in the CSS so that it remains in its original position (even though I just want it to stay within the column it originates from). But which values should I use? I attempted this CSS adjustment:

.affix {
    top: 20px;
    left: 62%;
    width: 25%;
}

While this tweaking somewhat resolves the issue (with slight discrepancies in positioning and width), it fails to adapt properly when viewed in different browser window sizes. Does this imply that I must include various media queries? Alternatively, could I compute these widths based on column proportions etc.? I have some basic knowledge of SASS - would utilizing this be a viable option to calculate these dimensions through bootstrap compilation?

Moreover, if anyone can propose how I can indicate which chapter is currently being viewed in the sidebar (similar to the behavior on the Bootstrap site), that would be greatly appreciated!

Answer №1

To ensure your affix property stays pinned to the right side in CSS, make sure to include right: 0;. I've gone ahead and prepared a working model on CodePen for you to review below.

If you want to update the design of the links based on their position, apply the scrollspy class to the parent ul and then customize the styles of the a links accordingly.

Take note of the additional classes added to the div and ul that contain the navigation elements (li).

For a responsive layout, be sure to define the necessary column widths for xs, sm, and md screen sizes as well.

Bootstrap Affix Right-Side Example

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

Creating a wider background color for active nav bar links in CSS - A step-by-step guide

I've been working on customizing a CSS navbar and I've managed to get it to work as desired. However, I'm facing an issue with the active state background color, which seems to be the same width as the text itself. I've spent hours sear ...

Is Bootstrap failing to function properly in my Angular project?

During my work on an angular project, I decided to implement bootstrap CSS and js for styling. However, after completing the project, I noticed that the bootstrap was not functioning correctly. I found that when I used the CDN link in the project, the bo ...

Upon initial load, the masonry elements on the webpage collapse unexpectedly

Hey there! I'm currently in the process of creating my own personal website - an online portfolio. While this is my first attempt at building a website from scratch, I must admit that I am quite new to HTML, CSS, JavaScript, and PHP. In fact, my know ...

As I hover over this bootstrap button with the class "btn-info", its background color fades away

Can anyone explain why this button loses its background color when I hover over it? Here is the code for the button: <nav class="navbar navbar-default navbar-static-top" role="navigation"> <div class="container"> <button type="butt ...

What is the best way to customize the default button style for buttons in Angular Datables?

After integrating buttons into my Angular Datatables, I noticed that they have default styling, which makes them stand out from the rest of my web page (refer to the Column Visibility button in the screenshot below): https://i.sstatic.net/w7Y8g.png I att ...

Overflow issues with flexbox design on mobile devices

Hello, I'm currently working on creating a sliding panel of images. While I have successfully implemented it, I am encountering some browser compatibility issues. The sliding panel functions perfectly on Chrome desktop, however, when viewed on mobil ...

Set the fixed position using the RN StyleSheet

Currently, I have a rendering setup for an item in a list that looks like this: return ( <View style={styles.item}> <View style={styles.nameAddressContainer}> <Text style={styles.customisedName}>{place.customisedName}&l ...

Utilizing media queries to tailor the pre-designed website and ensure adaptability

I find myself in a situation where I need to make adjustments to my current website to ensure it fits properly on smaller desktop screens. While the site is viewable on all screen sizes, issues arise with screens as small as 14 inches, resulting in an unwa ...

Several treeviews for selecting data

I need some help with a specific assignment. The back end code is all set, but I'm struggling with the UI component. The task requires two tree views, one on the left and one on the right. The left tree view will contain states with multiple children, ...

How can I adjust the positioning of List Items (LI) when using an image as a bullet point?

Looking for some CSS help! .ul{ list-style-image:url(/images/bullet.png) } I have a 20 x 20px bullet.png, but the text is displaying at the bottom of the image. I want to center the text inside the image without moving the entire bullet. Any suggesti ...

How to make a DIV element the same width as a TABLE element

Within my container DIV, there are three elements: two banner DIVs (representing a header and footer) and a wide TABLE. Despite the horizontal scrolling required for the large TABLE, I need the banner background colors to extend the full length of the DIV. ...

Tips for showcasing beautifully formatted XML content on a webpage

I have some XML data that I want to display on my website, but I'd prefer to show it in a styled format like a bootstrap table. However, I'm not sure how to go about doing this. Here's an example of the XML: <?xml version="1.0" encoding ...

The position property in CSS does not keep the <script> tag fixed in place

Struggling with keeping a .js validation script in a fixed position on a webpage. Here is the CSS code: div.fixed { position: fixed; bottom: 0; left: 0; } HTML <div class="fixed"> <script src="http://my.gblearn.com/js/javascript.js"></ ...

Tips for ensuring Opera browser compatibility with buttons using the CSS background image property

Is there a way to make background images work on buttons in Opera web browser using CSS? I've tried using the background image property, but it doesn't show up when I use Opera. Strangely enough, it works fine in Firefox. However, I have noticed ...

How can you align half of a circle on the bottom-center of a rectangle in a responsive way?

I'm working on a design where I have a large div taking up the width and some of the height, with a smaller circle that needs to be positioned half at the bottom/center of this div and half right after it. Everything seems to work fine until I increas ...

Can you explain the concept of image sprites and how they should be utilized?

When implementing image sprites in css, what approach do you typically take? Is it advisable to consolidate all the images on my website into a single image sprite? Are there significant benefits to doing so? How challenging is it to manage and update th ...

Horizontal image scrolling problem across different browsers

Check out my Fiddle. I'm having trouble with scrolling on different browsers. In Chrome, the scroll behaves as expected and stops when the content ends. However, in Firefox, it keeps scrolling even after reaching the end despite setting a fixed width ...

Showing text and icons side by side in the mobile view

How can I align individual icons (created with WordPress) and text on the same line? It's displaying fine on desktop screens but not on mobile devices. Can someone please check the image attachment and suggest a CSS solution? Thank you! Best regards ...

What is the best way to place a list below another list, which also includes a sub-list, in a responsive website design without causing the main lists to overlap

I have lists containing sub-lists, and I want to ensure that when the window screen is shrunk, the lower lists do not overlap the sub-lists of the upper ones. HTML markup - <div class="row-fluid"> <ul> ...

Images for navigating forward and backward in a jQuery datepicker

I'm experimenting with setting custom images for the previous and next month buttons. I attempted to utilize the prevText / nextText options of the datepicker in order to include a span with my own CSS class definition. However, this resulted in the c ...