Discovering the precise breakpoint in the Bootstrap grid system is essential

I have incorporated bootstrap into my home page layout with a main content column occupying 9 units and a sidebar column taking up 3 units. Within the sidebar, I have set the div element to have a position of fixed. When viewed on smaller screens, Bootstrap moves the sidebar to the bottom, which is fine. However, in that scenario, I require the sidebar's position to be relative instead. I am currently utilizing JavaScript to monitor screen width changes and adjust the position property accordingly. My concern is that Bootstrap may shift the sidebar below when the screen size is less than 972 pixels. Is there a way to accurately determine the exact width at which Bootstrap will reposition the sidebar? Any assistance would be greatly appreciated. Thank you. Alternative methods are also welcome.

<div class="container-fluid">
<div class="row">
    <div class="col-md-12">

        <div class="row">
            <div class="col-md-9">

                <div class="content"></div>


            </div>


            <div class="col-md-3">


                 <div class="sidebar"></div>


            </div>

        </div>

    </div>

</div>

The script:

$(document).ready(function () {
    if ($(window).width() > 972) {
            $('.sidebar').css('position', 'fixed');

        }              
});

Answer №1

Information regarding this can be found on the front page of Bootstrap.

/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */

/* Small devices (tablets, 768px and up) */
@media (min-width: @screen-sm-min) { ... }

/* Medium devices (desktops, 992px and up) */
@media (min-width: @screen-md-min) { ... }

/* Large devices (large desktops, 1200px and up) */
@media (min-width: @screen-lg-min) { ... }

The xs category refers to sizes less than 768px.

To have precise control over your layout, utilize all sizes - lg, md, sm, and xs - and customize for each screen size accordingly.
Selecting just one like lg will result in changes during resizing.

If you need assistance with your second question, check out this Fiddle.

I've set up a full-screen Fiddle for you so that when you resize the window, you can observe how two areas remain side by side.
This should give you the desired level of control.

<div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 bg-success block">

</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 bg-primary block">

</div>

Additional:

Press F12

Answer №2

You have chosen the md (Medium devices) bootstrap breakpoint for your layout.

With this setting, when the screen width is 992px or wider, the content will be displayed side-by-side with the main div. If the width is 991px or less, it will shift below the main content.

Check out more about grid layouts in Bootstrap here

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

javascript execute a function when a click event occurs

I came across this code online that successfully creates a button document.write(nomedispositivo) var r=$('<input/>').attr({//beginning of button type: "button", id: "field" , value: "Turn On", However, when I add the line: on ...

When attempting to send a GET request to the server, there is no response received, although the

I am having an issue with an ajax request I am sending to my server using jQuery's get function. The request is being sent successfully, as Firebug shows a 200 status code, but the server does not provide any response. Even when I enter the address di ...

Guide to passing the parent state as a prop to a child component and enabling the child to modify the state

I have a situation where my parent component holds 4 buttons to set a payment state, and I need to pass this state to a text field child component. Additionally, I want the text field to be editable so that the state can also be modified through it. My att ...

Encountering the AngularJS .Net Core routing $injector:modulerr error

I'm currently learning about .Net Core and AngularJS by following tutorials. However, I've encountered an error while attempting to implement client routing in the newest version of .Net Core with default configuration. The AngularJS error I rece ...

Attempting to grasp the concept of Promises in Angular 2

I have encountered an issue while working with the Google API service and I am stuck at the promise response stage. Here is the code snippet for reference: getPromise: Promise<any>; loadSheets: Array<any>; constructor(public _checkAuthApiServ ...

Ajax is malfunctioning and defaults to the initial method and action

I am facing an issue with ajax not working for a form, except for one form that works perfectly with AJAX. I have tried various solutions such as changing input to button and altering the type from "submit" to "button", experimenting with different jQuery ...

Attempting to modify the background hue of a grid component when a click event is triggered

I am struggling with the syntax to change the color of an element in my grid when clicked. I have attempted different variations without success. Being new to JavaScript, I would appreciate some gentle guidance if the solution is obvious. JS const gri ...

The shadow effect in three.js differs from that in Unity 3D

When I import a 3D model in .fbx format to my scene using three.js, I noticed that the shadow effect is not as sharp as when using Unity. The shadows appear too blurry. Is there a way to adjust the shadowMap setting in three.js to match the shadow quality ...

Retrieving a particular section within a <div> element from a webpage

I have been utilizing aiohttp and lxml for web scraping purposes to extract values from webpages. I have successfully implemented the following functions: def get_sr(page, tree): sr = tree.xpath(".//div[@class='competitive-rank']/div/text() ...

The matMul function encountered an error due to a mismatch in the inner shapes of the Tensors. The shapes provided were 684,1 and 2,1, and the transposeA and transposeB parameters were both set

I am completely new to the world of AI and tensorflow.js. Currently, I am following a Machine Learning course by Stephen Grider. I was expecting an output after running the code below, but instead, I encountered an error. Can someone please assist me? Her ...

Ensuring Radio Button Selection is Valid

Has anyone had success validating radio buttons using Javascript? I'm having some trouble and would appreciate any help. Here is the code I've been working with: <form action="submitAd.php" method="POST" enctype="multipart/form-data" name="pa ...

The animatedModal.js dialog box is causing the link to be unclickable, despite having a z-index of -9999

I am currently utilizing animatedModal.js for creating simple dialog boxes on my website. Everything is functioning perfectly, except for one issue - I am unable to click on the link to my logo at the top of the page because the modal with opacity:0; z-ind ...

Tips for incorporating the multiply times async function into mocha tests

I am attempting to utilize the async function foo multiple times in my mocha tests. Here is how I have structured it: describe('This test', () => { const foo = async () => { const wrapper = mount(Component); const button ...

The Daterangepicker function moment() outputs numerical values

Within my .cshtml file, I have integrated a daterangepicker.js script. This page retrieves the date range (from date, to date) from a parent page using ViewBag. The code snippet is as follows: var _FromDate; var _EndDate; $(function () { var from1 = ...

Why isn't my redirection functioning properly?

My code is having an issue with the redirect function being called too early, causing the last file of a batch upload to fail. I've been searching all morning and trying different solutions without success. function uploadFile(something, callback) { ...

What is causing the recurring failure of file input changes to take effect?

Here is the code snippet I'm working with: <input type="file" #fileInput ng2FileSelect [uploader]="uploader" (onFileSelected)="onFileSelected($event)" /> Along with the handler function: public onFileSelected(e: Fi ...

Ensure that the value in the array is verified using jQuery for errors

HTML <table id="gwForm"> <tbody> <tr data-id="1"></tr> <tr data-id="2"></tr> </tbody> </table> Script var ids = []; $("#gwForm tbody tr").each(function(index, el){ ids.push($(el).data ...

What are the steps for initializing a session in Vue.js with Django upon a successful login?

Upon successful login, I want to redirect to a page indicating success and also include a session. How can this be achieved? I am using HTML with Vue.js for the front end and Django for the back end. Below is my Vue.js script for the login: <script> ...

Tips for incorporating symmetrical values using jquery

I am facing a challenge with the following markup: <div class="container"> <figure></figure> <figure></figure> <figure></figure> </div> My task is to add a symmetrical element for each of the fi ...