Panel with Bootstrap Collapse feature causes a slight movement when padding is applied

After applying the collapse behavior to a panel element, I noticed that the animation stops abruptly at the padding of .panel-body, causing it to snap instantly to height. This issue can be observed in the basic example on codepen: http://codepen.io/FiveSixTwo/pen/NRQLPo

<div class="container">
  <div class="panel panel-default">
    <div class="panel-heading" role="button" data-target="#test" data-toggle="collapse">Test Heading<span class="btn-collapse-header glyphicons glyphicons-chevron-up"></span></div>
    <div id="test" class="panel-body collapse in" aria-expanded="true">
      <p>Laoreet ac, aliquam sit amet justo nunc tempor, metus vel placerat suscipit, orci nisl iaculis eros, a tincidunt nisi odio eget lorem nulla condimentum tempor mattis ut vitae feugiat augue cras ut metus a risus iaculis scelerisque eu ac ante fusce
        non varius purus aenean nec magna felis fusce vestibulum.</p>
      <p>Laoreet ac, aliquam sit amet justo nunc tempor, metus vel placerat suscipit, orci nisl iaculis eros, a tincidunt nisi odio eget lorem nulla condimentum tempor mattis ut vitae feugiat augue cras ut metus a risus iaculis scelerisque eu ac ante fusce
        non varius purus aenean nec magna felis fusce vestibulum.</p>
      <p>Laoreet ac, aliquam sit amet justo nunc tempor, metus vel placerat suscipit, orci nisl iaculis eros, a tincidunt nisi odio eget lorem nulla condimentum tempor mattis ut vitae feugiat augue cras ut metus a risus iaculis scelerisque eu ac ante fusce
        non varius purus aenean nec magna felis fusce vestibulum.</p>
    </div>
  </div>
</div>

Semi solution:

.panel-body {
  padding: 0;
  p {
    padding: 15px 15px 0;
    &:last-of-type { padding-bottom: 15px; }
  }
}

This temporary fix involves removing the padding from .panel-body, but it's not ideal as it may require extensive CSS adjustments throughout the app.

My goal is to maintain the padding on .panel-body while ensuring a smooth collapse animation without any sudden changes in height.

In my pen, I have commented out the solution CSS to demonstrate the issue more clearly.

One straightforward approach could be enclosing everything within another div with padding, although this isn't significantly better than the semi-solution. I'm looking for a universal CSS or even JS solution, but haven't found one yet.

While Bootstrap has its advantages, the more I work with it and expand my app, the less satisfied I am with its limitations.

Answer №1

Visit this CodePen link for more details

It seems like the issue may be related to missing the div.panel-group that should wrap your panel.

You can refer to the Accordion syntax at this page on Bootstrap website

<div class="container">
  <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingOne">
      <h4 class="panel-title">
        <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          Collapsible Group Item #1
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
      <div class="panel-body">
              <p>Lorem Ipsum placeholder text.</p>
      <p>More placeholder text here for demonstration purposes.</p>
      <p>Even more placeholder text to fill out the content area.</p>
      </div>
    </div>
  </div>  
</div>
</div>

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 Javascript and JQuery to create an alert that pops up upon loading the page is not effective

I am having trouble making an alert show up when my website loads. The Javascript code is functional when directly included in the HTML, but once I move it to a separate file named script.js and link it, nothing happens. Can someone please help me identify ...

Responsive tables in Bootstrap 4 that are nested

I am currently utilizing Bootstrap 4. I have a complex table structure where I want only the second column and onward to be scrollable. The challenge is making this specific part of the table responsive while keeping the rest static. I attempted to nest a ...

Open a JavaScript file to retrieve data from a nearby JSON object

I've been trying to access a local JSON file using a JavaScript file, but for some reason it's not working. Even though I'm sure the URL is correct, the code keeps failing to retrieve data from the JSON object. JavaScript file: var pieData ...

What is the best way to display JSON response data in a datatable by utilizing jQuery AJAX requests?

I am attempting to implement a date range search using jQuery Ajax and display the data in a datatable. Below is the PHP controller code I am using. public function date() { $date_from = date('Y-m-d H:i:s', strtotime($this->input->pos ...

How can you use jQuery.ajax to solely fetch the status code without downloading the entire document?

My application relies on the use of jQuery.ajax to check if a particular resource exists by constantly polling it. Once the resource is no longer returning a 404 status code, the app redirects to view that resource. However, I am concerned about downloadin ...

The dropdown in the Material UI GridList appears excessively wide

Currently, I'm attempting to design a grid-shaped drop-down menu in Material UI. Most of the dropdowns available in the documentation are either a single column or a single row. I tried utilizing a menu component that includes a GridList, which almost ...

I created some jQuery code that modifies a button when it is hovered over, however, I ended up writing the code individually for each button. What steps can I take to turn it

Is there a way to turn the code for each button on my website into a jQuery function that can be applied to any button? This is how the code currently appears: $(document).ready(function() { $("#linkXML").hover( function() { ...

Utilizing Jquery and php for form validation

I'm currently working on a form that includes radio buttons and I am attempting to validate it using jq/$.ajax before submitting the information in php. form.php <tr> <td class="h"><span class="txt_wht">t1</span></td> ...

Placing a materialUI circular progress bar on top of the circular icon

I'm striving to add a circular progress bar that surrounds a circular icon with a visible space between the two elements, just as depicted in the image below. Although I successfully positioned the circular progress bar around the icon, creating adequ ...

What is the best way to show personalized messages to users using modal windows?

Encountering bugs while trying to implement user messages in modals. function displayMessage(title, description) { var myModalErrorMessage; $("#customErrorMessageTitle").text(title) $("#customErrorMessageDescription").html(description) myModalEr ...

What is the best way to trigger the jQuery-File-Upload event within this function?

Before uploading a file, I want to check the API first. $('.file_upload_button_wrapper').on('click', function () { // perform check here $.ajax({ url: '/?app=files&getfile=ajax%2Fupload.php', ...

Dealing with Memory Leaks in AngularJS and Jquery

My web application has been created with a combination of jQuery and Angularjs. I am currently on the lookout for patterns that could lead to memory leaks in Angularjs. I have used Chrome profiler as a tool to find memory leaks, but unfortunately haven&a ...

Ensure that the second card occupies the entire column using Bootstrap 5

If I have a row with 2 columns, how can I ensure that the second card in a column fills the remaining space in the column? I attempted to use classes like flex-fill and flex-grow-1, but they did not seem to have any effect. Feel free to check out my code ...

Using jQuery to select the child element of the parent that came before

Recently, I've been experimenting with creating animations using CSS and jQuery. While it has been successful so far, I'm now looking to take it a step further. Specifically, I want information to appear on top of an image when the user clicks on ...

If the width of the table is set to 100% in the CSS, the legend in the Flot chart will automatically shift to the

When the CSS for the table is set to { width:100%}, the Flot chart's legend moves to the left side. Is there any way to maintain the table { width:100%} while also preventing this shift, considering that the CSS is applied site-wide? Here is a jsfid ...

Fade background when the youtube video in the iframe begins playing

Hey there! I'm looking to create a cool effect on my (wordpress) site where the background dims when a YouTube video starts playing. The video is embedded in this way: <iframe frameborder="0" width="660" height="371" allowfullscreen="" src="https ...

When I added a border in CSS and inserted a link within that border, the link ended up extending beyond the border itself

I decided to create a border class for my link and placed the link inside that border. However, when I view it on a responsive device, the link extends beyond the borders while the text within the border remains intact. How can I fix this issue? Here is m ...

What is the most effective way to alter the font within this Bootstrap template?

Check out the source code on Github. I've been attempting to modify the font-family for both h1 and body elements, but it's not working as expected. I must be overlooking something simple, but I can't seem to pinpoint the issue. It's d ...

Are you in need of a GWT/GXT tag editing tool?

Does anyone know of a GWT or GXT based tag editor control that is similar to the ones found at http://tagedit.webwork-albrecht.de or http://levycarneiro.com/projects/tag-it/example.html, or the one used on the StackOverflow edit page? I've searched Go ...

Semantic UI dropdown field not displaying selected option text

I've encountered an issue while working with React Semantic UI. I'm trying to render a dropdown and have configured it so that the selected option's text should display in the field. However, when I choose an option from the dropdown, instea ...