Incorrect width of JQuery Accordion

I am facing an issue using a table with JQuery UI Accordion where both the header and contents should have 3 columns of fixed width. Strangely, the first column in the contents is not following the CSS rules while the header appears to be fine. Here is a link to my JSFiddle for reference: http://jsfiddle.net/qm12h9tL/

Below is the code snippet:

<script>
$(document).ready(function() {  
    $('#topics').accordion({
        collapsible:true,
        header:'.topic',
        content:'.lessons'
    });
});
</script>
... (rest of the code)

Edit1: I tried rearranging the HTML structure as shown below but it did not work:

<table id="topics">
        <tr class="topic">
            ... (content here)
        </tr>
        <tr class='lessons'>
           ... (content here)
        </tr>
</table>

Edit 2: Surprisingly, adding more lessons to a topic seems to create complications! Check out this updated fiddle with additional lessons added: http://jsfiddle.net/qm12h9tL/11/. Updated code snippet can be seen below:

<table id="topics">
    ... (updated content here)
</table>

Answer №1

After making an adjustment to your header (<tbody>) element by adding a display: table property, you may have noticed that it caused some layout issues. Removing this property then leads to jQuery UI introducing a display: block style to the <tr> element, changing its display to block level. To resolve this, I suggest setting display: table-row for the <tr> element.

However, another problem arises as jQuery adds a span with an icon within the <tr>, creating an extra cell. To address this, apply the following CSS :

table span
{
    display: none !important;
}

This should resolve the issue.

For the updated version, refer to this fiddle: http://jsfiddle.net/qm12h9tL/8/


Update: resolved collapsible: true

Answer №2

It seems that the display:table style attribute in your code is causing some layout issues, specifically on the first tbody tag. Is it possible that this is a leftover from copying and pasting code?

Answer №3

A solution has been implemented through a hack

.ui-accordion .ui-accordion-header{
  display: table-caption !important;
}

It should be noted that display: table-caption; is not supported in IE7 and earlier versions. IE8 requires a !DOCTYPE declaration. IE9, however, does support these values.

$(document).ready(function() {
$('#topics').accordion({
collapsible:true,
header:'.topic',
content:'.lessons'
});
});
.accordion-container {
  width: 100%;
  background-color: #ff0;
}
#topics{
  width: 400px;
}
.name {
  width: 70%;
}
.cards {
  width: 15%;
}
.percentage {
  width: 15%;
}
.ui-accordion .ui-accordion-header{
  display: table-caption !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/south-street/jquery-ui.css" rel="stylesheet" />
<div class="accordion-container">
  <table id="topics">
    <tbody class="topic" id="t1">
      <tr>
        <th class="name">Topic 1</th>
        <th class="cards">10 cards</th>
        <th class="percentage">100%</th>
      </tr>
    </tbody>
    <tbody class="lessons">
      <tr>
        <td class="name">Lesson 1</td>
        <td class="cards">10 cards</td>
        <td class="percentage">100%</td>
      </tr>
    </tbody>
  </table>
</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

Unique and responsive grid styling with CSS

Is it possible to create a responsive grid like the one shown in the image below? I attempted to use absolute positioning for all blocks, but I'm having trouble making it responsive... I should note that the styling will be generated dynamically usi ...

Double firing of select_node event in JSTree

I have created a select_node event, but it seems to be firing twice when we select a node. The alert I set on the select_node event is being triggered twice. In the JStree initialization, I have also specified a check event. $('#div_vocabulary_t ...

What is the best way to navigate to the bottom of a page when new data is added?

I've created a chat feature in my Ionic app, but the issue is that when a user receives a new message while being on the chat screen, the view doesn't automatically scroll down to show the new message. The user has to manually scroll down to see ...

How to Arrange Information Harvested from While and For Loops?

I am attempting to display the posts of a user's friends, similar to the layout of Facebook's main page. Currently, to echo out a user's friend's posts, the database table for that user contains a reference to a text file. In my case, t ...

The Safari browser is having trouble rendering the website's CSS and HTML properly

Check out this example of how the website should look on Chrome for Android: https://i.stack.imgur.com/RzUSp.jpg And here is an example from Safari on iPad Mini 2: https://i.stack.imgur.com/PAj2i.jpg The Safari version doesn't display the proper fon ...

Dynamic scaling and positioning of multiple images in relation to each other using CSS

I am currently working on layering images over a large logo and making sure it remains responsive. I want the overlaid images to maintain their position on the logo even when the browser window size is reduced. Here is what my current browser display look ...

Using JQuery to handle various input fields, forms, and submission actions

I have multiple forms displayed as rows within a table. At the end of each row, there is a submit button. Upon clicking this button, my JQuery function generates two text boxes and another submit button dynamically. My goal is to capture POST variables fro ...

Populate dropdown menu options using dynamic data from a database

I am seeking assistance with the following: I have two fields: 1. Date - utilizing jQuery datepicker 2. Dropdown - Filled with student IDs My goal is to select a date, such as 03/09/2012, and retrieve all student IDs present on that day (let's say t ...

Manipulate the value of an HTML element's style parameter with jQuery

How do I change an element's style property using jQuery? This is the HTML code I am working with: <div id="template" style="width:200px; height:200px; border:none;">blabla...</div> I attempted to do this: $('#template').attr ...

Locate the nearest preceding element using jQuery

I am searching for a solution similar to what this individual is asking for, but the element I need to match may not be a direct sibling. Given the following HTML: <h3> <span> <b>What's up?</b> </span> & ...

What is the best way to execute a function based on the width of the screen?

Two functions need to be called based on the screen width. Here is one attempt: var winWidth = $(window).width(); var sections = function() { $('.image').each(function(){ var $this = $(this), x = $this.find('img'). ...

Utilizing Google Maps autosuggest with JQuery - Trigger load upon selection

Currently, the Google map code operates in the following manner: Upon entering text into the input box, a list of suggestions loads. When you click on one of these options, it places it into the input box. However, you then still need to click "find" to d ...

CSS inline-block problem - Either everything stays or everything collapses

I am facing a specific scenario where I have three inline-elements. Two of them are essentially the same, but the one in the middle has an unknown width. I want to achieve one of two things: Have all three elements display inline on the same row If the ...

<p> The box is massive, and its size is a mystery to me

https://i.sstatic.net/xPoDz.png Why is the box around my paragraph tag so large? I suspect this could be why I am unable to move the <p> tag down with margin-top: 50px; .train p { margin: 0; font-size: 2.5vw; } <div class="train"> < ...

How can you utilize the Array submission syntax within HTML coding?

I currently have numerous input fields within a form, and some of them are structured like this: <input name="agents[]" type="file" /> Additionally, imagine there is a plus button next to this field as shown below: <img src="plus.jpg" id="some_ ...

Using gradient colors for the background on the ::selection pseudo-element

Can you apply a gradient color to CSS ::selection? I tried using the following code: ::selection { background-image: -webkit-linear-gradient(left, #ee4037 0%, #eb297b 100%); } However, it did not have the desired effect. ...

Optimize your texture loading process by dynamically swapping out low resolution textures with high resolution ones to enhance overall visual quality

In my current ThreeJS project, I have encountered an issue when trying to swap one texture with another. The problem arises when the UV's become completely distorted after the texture switch. Below is the snippet of code that showcases how I am attemp ...

Displaying information from an array in a view and manipulating it using JavaScript

Having trouble displaying array data in a customized way. Here is how my array structure looks: array:2 [▼ "folder1" => array:5 [▼ 0 => "4.png" 1 => "2.png" 2 => "1.png" 3 => "3.png" 4 => "5.png" ] "folder2" ...

Tips for transferring a JavaScript variable to a servlet

I have implemented the selectable jquery plugin on my JSP page. I need to pass the selected string as a parameter to a servlet when the form is submitted. $(function() { $("#selectable").selectable({ stop: function() { var result = ...

What are the signs of a syntax error in a jQuery event like the one shown below?

One of my forms has an ID attribute of id ='login-form' $('#login-form').submit(function(evt) { $('#login-button').addClass('disabled').val('Please wait...'); evt.preventDefault(); var postData = ...