"Endowed with improper dimensions, the BootStrap collapse feature

Yesterday, I posted about an issue with BootStrap and panel collapsables causing graph sizes to become distorted. The post was locked because there was no accompanying code. I have now created a code snippet for you all to see the exact problem I am facing: http://jsfiddle.net/oeq980ts/1/

<p>the code can be found on jsFiddle :) </p>

To refer back to my previous post from yesterday, here is the link:

The issue becomes evident when comparing collapse 2 to collapse 1 after running the jsfiddle.

Yesterday's post:

http://www.w3schools.com/bootstrap/bootstrap_ref_js_collapse.asp

While experimenting with Bootstrap's collapse feature, I noticed a strange behavior with .collapse (hides content) and .collapse-in (shows content).

I initially set collapse1 as .collapse-in so that its contents, including a graph (with min-width:310px; height:400px), would be displayed properly. However, when I opened collapse2, the same graph appeared significantly undersized, almost half the width. After some trial and error, I realized that the graphs only display correctly when using the class collapse. If just using panel-collapse collapse, clicking to reveal the content results in a completely disproportionate size.

Additionally, if .collapse-in is applied, users can collapse/unclapse while the graph in that section remains visible. This might not be ideal for those who prefer the content hidden by default.

Although I probably won't be using this particular setup, I was curious about the rationale behind this behavior.

https://i.stack.imgur.com/9g8Kb.png

https://i.stack.imgur.com/VPoB7.png

Answer №1

Here is a suggested approach to achieve this:

Steps:

  1. Initially display all collapsible elements by adding the in class to the collapse div - This will ensure they are visible and fitted to their container as desired. Therefore, the collapses should look like this:

    <div id="collapse2" class="panel-collapse collapse in">

  2. Subsequently, hide them using jQuery (remove the in class from all divs that you want to hide)

    $(document).ready(function(){
        $('.collapse').not(':eq(0)').removeClass('in');
    });

Following your setup in the fiddle, I have hidden the first collapse option.

Please review your updated jsFiddle.

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

Using Express.js and Angular for user authentication and session management

In my current project, I am utilizing expressjs and angularjs to create an app. The setup involves expressjs serving a single .html file that houses an angular single-page-application. All routing is handled by angularjs, while expressjs provides web servi ...

Ensuring the aspect ratio of images stays consistent within a flexbox using CSS

How can I create a grid of images without any spacing in between them? I want the width to be 100% of the parent element and each column to have the same size, for example, 20%. Using flex takes care of the columns, but I'm struggling with making the ...

Mastering the nav-item class in Bootstrap 4 for optimal navigation functionality

When I look at the examples in the documentation, I have noticed that the .nav-item class is not doing anything when I inspect my nav bar (the class doesn't show up in the console)... Although this isn't a major issue as I can apply my own style ...

Issue with floating date and time not functioning properly in ICS file for Yahoo Calendar

I have set up a calendar event in Google, Apple, and Yahoo calendars for each individual customer. The event is scheduled based on the customer's address at a specific time, so there should be no need for timezone conversion. However, I encountered an ...

What are the methods for integrating a JavaScript framework in a Rails application without utilizing any gems?

I am seeking guidance on integrating frameworks such as angularjs, polymer js, bootstrap, etc., into a Rails application without relying on corresponding gems. The reason for this approach is that the availability of gems may change and some projects may ...

Error in vue.js: Unable to call this.$emit as it is not a function

export default { mounted() { setTimeout(function() { this.$emit('onLoad') }, 4000); } } //views/Load.vue I want to redirect to another page after the page has been accessed for 4 seconds. <template> <d ...

Eliminate event listener using unique identifier

Is there a way to retrieve information about all event handlers for an element in JavaScript? $._data($('#element_id')[0], "events"); This will provide a detailed record of every event handler attached to the element. 0: {type: "c ...

A JQuery function linked to the click event of the body element triggers another click event right away

$().ready(function(){ $("#move-to").click(function(){ $("body").bind("click",function(){ alert("foo"); }); }); }); Why do I receive an alert message of "foo" immediately after clicking on "move-to"? When I bind the " ...

Could someone provide some clarification on this callback related to node.js?

With the abundance of node.js tutorials available showing how to create a server, it can be overwhelming as they are all coded in different ways. The question then arises - when should you write it one way versus another? Unfortunately, none of the tutoria ...

Issue with fuse-box: unable to import ReactDOM

Recently, I decided to switch from webpack to fuse-box for my side project. Everything is compiling without any issues, but when I try to load it, an error pops up: I downloaded a React demo code and it works fine. Additionally, there are no problems wit ...

Refresh the page with cleared cache using window.location.reload

Is there a way to reload a page using JavaScript and still clear the cache, ensuring that the refreshed page shows the latest content from the server? It seems that other browsers are not displaying the most up-to-date versions of the content. Anyone have ...

Trouble with retrieving dates in ISO format

My collection stores the date of birth field in ISO format, for example: ISODate("1980-01-01T20:20:19.198Z") However, when I use a date time picker on my HTML page, it displays the date like this: 01/01/1980 Unfortunately, when querying for the date of ...

React App stalled due to continuously running function

In this section of my React app, the createBubbles function is functioning properly. However, I am encountering an issue where the entire app freezes when navigating to another page after visiting this one. The console displays the following errors and de ...

Build a Node.js application with Express to host static files

I am attempting to provide my static files "web.html" and "mobile.html", but I want them to be served only if the user is accessing from a web or mobile device. After some research, I came up with this code: var express = require('express'); va ...

The navigation bar on the web app is functioning properly on Android devices but experiencing a CSS problem on

My Nextjs web app includes a navbar with a hamburger menu, logo, and avatar. The navbar functions perfectly on desktop in Chrome, Mozilla, Brave (in developer tools mobile mode), and on Android phones using Chrome. However, when accessed from an iPhone X, ...

What is the most efficient method for exporting Express route functions for promise chaining?

Currently, I am in the process of refactoring an API route to utilize ES6 promises instead of callbacks, so as to avoid callback hell. Upon successful conversion to a promise chain, my intention was to extract the .then() functions into a separate file fo ...

deactivating image mapping on mobile media screens

I'm looking to disable my image map on mobile screens using media queries. I've attempted to include some javascript in the head of my html file, but I encountered an error: <script src="http://code.jquery.com/jquery-1.11.3.min.js"></s ...

Attempting to determine the correct callback URL for a custom login screen on Auth0

Struggling to implement a custom login screen for my Angular app locally by following this guide. The issue lies in the fact that my login callback is not being triggered. The original login URL is http://localhost:9000/#/login angular.module('myApp ...

Creating a primary index file as part of the package building process in a node environment

Currently, I have a software package that creates the following directory structure: package_name -- README.md -- package.json ---- /dist ---- /node_modules Unfortunately, this package cannot be used by consumers because it lacks an index.js file in the r ...

Exploring alternatives to ref() when not responsive to reassignments in the Composition API

Check out this easy carousel: <template> <div ref="wrapperRef" class="js-carousel container"> <div class="row"> <slot></slot> </div> <div class=&q ...