Adjusting the layout of tables for an accordion design

I am facing an issue with displaying the accordion in a table layout. When I expand them, the arrangement gets disrupted.

To see the table layout for the accordion, you can check it here.

<div ng-controller="AccordionDemoCtrl">
<label class="checkbox">
    <input type="checkbox" ng-model="oneAtATime" />Open only one at a time</label>
<accordion close-others="oneAtATime">
    <accordion-group  heading="Static Header">This content is directly in the template.</accordion-group>
    <accordion-group heading="{{group.title}}" ng-repeat="group in groups">{{group.content}}</accordion-group>
    <accordion-group heading="Dynamic Body Content">
        <p>The body of the accordion group adjusts to fit the contents.</p>
        <button class="btn btn-small" ng-click="addItem()">Add Item</button>
        <div ng-repeat="item in items">{{item}}</div>
    </accordion-group>
</accordion>

When I click on the first accordion, it expands but also disrupts the one below it. The provided mockup looks like:

https://i.sstatic.net/2R2j2.png

Answer №1

The accordion component is sourced from the angular-ui-bootstrap library, which includes Bootstrap styling by default. To achieve the desired layout, utilize the Bootstrap grid system by utilizing the row and col classes.

In this specific example, the use of col-xs-4 ensures the display of all three columns within the fiddle.


   <accordion close-others="oneAtATime">
       <div class="row">

         <div class="col-xs-4">
            <accordion-group heading="Static Header">This content is directly in the template.</accordion-group>
            <accordion-group heading="Static Header">This content is directly in the template.</accordion-group>
            <accordion-group heading="Static Header">This content is directly in the template.</accordion-group>
         </div>  

         <div class="col-xs-4">
            <accordion-group heading="Static Header">This content is directly in the template.</accordion-group>
            <accordion-group  heading="Static Header">This content is directly in the template.</accordion-group>
            <accordion-group heading="{{group.title}}" ng-repeat="group in groups">{{group.content}}</accordion-group>
        </div>

         <div class="col-xs-4">
              <accordion-group heading="Dynamic Body Content">
                <p>The body of the accordion group expands to fit the contents</p>
                <button class="btn btn-small" ng-click="addItem()">Add Item</button>
                <div ng-repeat="item in items">{{item}}</div>
              </accordion-group>
              <accordion-group heading="Static Header">This content is directly in the template.</accordion-group>
              <accordion-group heading="{{group.title}}"ng-repeat="group in groups">{{group.content}}</accordion-group>
        </div>

    </div>

Here is the link to view the implementation on JSFiddle

It's advised to remove any custom CSS styles as they are unnecessary due to Bootstrap inclusion.

Additionally, refer to the Bootstrap grid documentation for further customization by using classes like col-sm-, col-md-, and col-lg- to adjust layouts for different screen sizes.


UPDATE: Building the Accordion Dynamically

To create an accordion dynamically from an array of data such as [item1, item2, ...], it is recommended to transform this data within the controller by splitting it into smaller arrays:

[[item1,item2,...], [item6,...],[item9, ...]]

Below is a simple function that can help achieve this:


function separateArray(arr, size) {
      var newArr = [];
      var colsLength = Math.ceil(arr.length/size);
      for (var i=0; i<arr.length; i+=colsLength) {
        newArr.push(arr.slice(i, i+colsLength));
      }
      return newArr;
}

Utilize the function as follows:

$scope.transformedGroups = separateArray($scope.groups, 3);

This will divide your data into 3 separate arrays:

[[item1, item2,...], [item6,...], [item9,...]]

You can then easily implement the 3 columns with:

<div class="row">
     <accordion close-others="oneAtATime">
         <div class="col-xs-4" ng-repeat="rows in transformedGroups">
           <accordion-group heading="{{group.title}}"  ng-repeat="group in rows">{{group.content}}</accordion-group>
         </div>
     </accordion>
</div>

View the working example on JSFiddle: here

Answer №2

If you're looking for a seamless layout solution, consider using bootstrap for this design. With bootstrap, you can create a table layout without the need for table markup and ensure that your data stacks neatly on smaller screen sizes, eliminating the risk of horizontal scrolling.

For optimal display at XS screen size (<=767px), make sure your data stacks properly:

<div class="col-lg-4 col-md-4 col-sm-4 col-xs">

If you prefer your data to stack by column rather than row, wrap the data into a single row and nest individual rows within the columns. Check out my fiddle here for a visual example.

UPDATE-9/20/17:10:30EST

In hindsight, utilizing a flex-container and flex-items may be a more efficient solution to meet your requirements. I've created a NEW FIDDLE as a starting point for you.

Answer №3

After examining your code, it seems that you have used CSS for the panel in the following way:

.panel{
  width:30%;
  float:left;
}

I recommend updating the CSS for the panel to the following instead:

.panel{
  width:100%;
  float:left;
} 

This modification should resolve the issue.

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

How can I integrate an angular-formly template with a custom UI/CSS library?

Seeking advice on incorporating a custom Angular-formly template into my application. I prefer not to use the Bootstrap template as I have my own UI/css library. Should I opt for angular-formly-templates-vanilla or angular-formly-templates-bootstrap and mo ...

How should I refer to this style of font?

After trying to implement a font from bulletproof @font-face as a template for my website, I am facing issues. My goal is to utilize the perspective-sans black regular font. Despite uploading the necessary files - including the css style sheet provided in ...

I found myself puzzled by the error message "Module protobufjs not found."

I am currently utilizing the node library known as node-dota2. I have completed all the necessary steps required by node-dota2, as outlined on this site: https://github.com/Arcana/node-dota2#installation-and-setup 1. Installed it using npm 2. Created a fil ...

Tips for implementing an autoscroll feature in the comments section when there is an abundance of comments

Having a large number of comments on a single post can make my page heavy and long sometimes. This is the current layout of my post comment system: Post 1 Comment for post 1 //if comments are more than 3 <button class="view_comments" data-id="1">Vi ...

Need help using JQuery to set the focus on the initial <select> element on a webpage?

Upon loading the page, I am looking to set focus on the initial element through JQuery. So far, I have managed to achieve this by using: $(":input:visible:first").focus(); or $(':input:enabled:visible:first').focus(); as described in a helpf ...

Is there a way to position the search bar on a new line within the navigation bar when the screen size is at its maximum width for mobile

I have a search bar on my navigation bar, but I am looking to move it to the next line within a maximum width if the screen display is extra small (xs) or for mobile devices. Below is the code snippet: <nav class="navbar navbar-expand-md fixed-top ...

Animating a CSS shape with the .animate method

I need help creating a dynamic graphic for my school project using css, jquery, and html. I want to make a rectangle that moves across the screen, but I'm having trouble getting it to work properly. Despite trying different variations of the animate f ...

Closing the video on an HTML5 player using an iPad

My task is to incorporate a video into a website with a button to close and stop the video. Once closed, an image will appear below. Everything works perfectly on all browsers. The issue arises on the iPad... On the iPad, the "close" button does not wor ...

Stripping away HTML tags from a JSON output

I'm attempting to retrieve a JSON result using jQuery. $.ajax({ type: "GET", url: "http://localhost:8080/App/QueryString.jsp?Query="+query, contentType:"text/html; charset=utf-8", dataType: "json", success: function(json) { if(data!="") ...

Understanding the user's preference for text alignment and managing how the text is displayed in a text area (or text field) within a ReactJS application

My latest project is an app that features multiple text areas. Personally, I use the app with two languages - English and another language that is aligned to the right. However, the default setting has the text-areas aligning to the left. To change this ...

Obtain a Compilation of Video Sources in an HTML5 Format

Hey there, I am using an HTML5 video. This is just an example <video width="320" id="video" height="240" controls> <source src="video.mp4" type="video/mp4"> <source src="video1.mp4" type="video/mp4"> <source src="movie.ogg" typ ...

Retrieving CSS properties of an element using JavaScript

How can I efficiently retrieve all CSS rules associated with a specific element using JavaScript? I am not seeking a particular solution, just looking to capture all CSS rules for the given element. For example, consider the following HTML code: <div ...

Steps for aligning a grid column to the same height as the element above it and moving it to the left side

I have a setup using material UI where I have a grid positioned on top of a Paper element. Within the grid, there is a text input field in the first column that I want to match the height of the paper element and be aligned with its left border. I have tri ...

"Enhance Your Website with Drag-and-Drop Cart Functionality using HTML

Seeking assistance from anyone who has the knowledge. I've searched through similar questions on this platform but haven't been able to resolve my issue. Currently, I'm working on developing a basic shopping cart using HTML5 (Drag and Drop ...

In my PHP script, I'm seeking a solution to include a numeric value and then

Greetings, I'm experiencing a peculiar issue where only the first section appears when I submit a number. Here is the code I've implemented and I would greatly appreciate any assistance or guidance. Essentially, my intention is to have a user red ...

Developing a progress bar with jQuery and Cascading Style Sheets (

Below is the code I'm currently using: <progress id="amount" value="0" max="100"></progress> Here is the JavaScript snippet I have implemented: <script> for (var i = 0; i < 240; i++) { setTimeout(function () { // this repre ...

Is it possible to stack one Canvas on top of another?

Right now, I am engaged in a process that involves: creating a canvas and attaching it to a division applying a background image through CSS to that canvas. drawing a hex grid on the canvas placing PNGs on the canvas. animating those PNGs to show "movem ...

Sortable lists that are linked together, containing items that cannot be moved

I have been trying to implement two connected sortable lists with disabled items using this sortable list plugin, but for some reason, I am unable to get it to work. Is there anyone who can provide assistance with this issue? <section> <h1&g ...

Guide to personalizing checkbox design using react-bootstrap

I am working with react-bootstrap and attempting to style a custom checkbox, as it appears possible but is not working. I have followed the documentation provided here. Here is the code snippet: import * as React from "react"; import { t as typy } from & ...

Finding the value of an input without having to submit it first and searching for it within a datalist

> Here is an example of HTML code <label>Person</label> <input name="PersonID" type="text" id="PersonID"> <label>Car Plate Number</label> <input name="PersonsCarPlateNumber" list="PersonsCarPlateNumbe ...