If viewed on a mobile device, separate the array (indexed list) into two rows

Currently, I am working on my Ionic project where I am trying to implement an indexed list horizontally instead of vertically. While the list looks good as it is now, I want to make sure it supports smaller screen devices too by splitting the list into two rows when the screen width is less than 700px.

The desired output can be viewed here: . And this is what I have accomplished so far: http://plnkr.co/edit/20T3fpKfAq7P0QQTddEo

$scope.alphabet = {
A: {
  name: "A",
  amount: 0
},
B: {
  name: "B",
  amount: 0
},
...
Z: {
  name: "Z",
  amount: 0
}
};
.button-alphabet {
  background: transparent;
  color: #777;
  width: 3.8%;
  border: 1px solid #999;
  display: inline;
}
.button-alphabet[disabled] {
  border: none;
}
.button-alphabet:nth-of-type(13):after {
  content: "\A";
 white-space: pre;
  border: 10px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="row center">
  <button ng-repeat="letter in alphabet" class="button-alphabet">{{letter.name}}</button>
</div>

I attempted to place the buttons inline and utilize the :after selector to add a line break after the 13th element, but haven't had any success yet.

When using JavaScript, I achieve the desired outcome, however, there seems to be an issue with indexing. Selecting the upper 'B' also selects the letter 'O' below it since they share the same index in the array. You can view the implementation here: http://plnkr.co/edit/Ima2dVxEsXVNPfljEsAF

I've searched various topics on Stack Overflow for a solution, but haven't found one that suits my needs. Is it possible to split the array into two rows programmatically? Can this be achieved solely with CSS or should I rely on JavaScript? Any assistance would be greatly appreciated.

Answer №1

To achieve this, utilize ng-repeat-start followed by ng-repeat-end to insert a block element as separator.

Example in HTML:

<button ng-repeat-start="letter in alphabet" ...>{{letter.name}}</button>
<div ng-repeat-end ng-if="$index==12" class="separator"></div>

In the CSS:

.separator{
    display:none;
  }
  @media screen and (max-width:700px){
    .separator{          
      display:block;
    }
  }

Check out the DEMO here

Answer №2

Initially, there was a syntax error involving the usage of ng-class.

Below is the correct syntax:

ng-class="{ current : $index == 13 }"

I have made the necessary adjustments to the code. While I cannot confirm if the visual outcome aligns with your expectations, I have implemented the ng-class for the 13th element and incorporated the CSS style referenced in your sample.

Check out this Plunkr example

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

Can you customize the "rem" values for individual Web Components when using Angular 2's ViewEncapsulation.Native feature?

I'm interested in creating a component with ViewEncapsulation.Native that utilizes Bootstrap 4 while others are using Bootstrap 3. Below is the component code with Bootstrap 4: import { Component, ViewEncapsulation } from '@angular/core'; i ...

What is the best way to create a basic accordion using only certain table rows?

I am faced with the task of transforming a HTML table that lists various items. Each <tr> within the table contains a unique title element, but there are cases where rows can share the same title indicating their relation. My goal is to implement jQu ...

The ng-repeat directive is failing to render the list item within the anchor tag

Here is the HTML code as seen in the text editor... <div ng-repeat="x in Result"> <a ng-href="https://domain.com/{{x.short_url}}"> <li class="viewer" id="{{x.user_id}}" style="background-image: url(https://domain.com/{{x.user_id}} ...

The jQuery function fails to execute when the script source is included in the head of the document

I'm relatively new to working with scripts and sources, assuming I could easily add them to the header and then include multiple scripts or functions afterwards. Everything seemed to be working fine at first, but now I've encountered a problem th ...

Leverage the power of Web Components in Vue applications

Currently, I am attempting to reuse Web Components within a Vue Component. These Web Components utilize the template element for formatting output. However, when I insert them into the Vue Template, they are either removed from the DOM or compiled by Vue. ...

Exploring the process of performing an AJAX JQuery HTTP request using JavaScript and PHP on the server side - any tips?

Greetings! I have developed a web application using HTML, CSS, and JavaScript. To enhance functionality, I have integrated Bootstrap and jQuery into the project. The application comprises both client-side and server-side components. Let's take a look ...

The event fails to propagate up to the parent component

I have a project structure set up as follows: https://i.stack.imgur.com/bvmK5.jpg The todo-form component triggers the created event and I am looking to handle this event in the todos component. todo-form.component.html: <form class="todo-form" ( ...

Align a div in the center with another div positioned to its left and floated

I am in the process of creating a footer with three components: a logo aligned to the left, a centered navigation menu, and a set of social icons on the right. I have encountered an issue where when I float the logo to the left, the list items within my na ...

Navigating Dynamically between tabs - A How-to Guide

I am working on a mat-tab Angular app where I need to dynamically generate links and transfer them to a navLinks object. Despite ensuring that the concatenation is correct, it seems like my approach is not working as expected. Here's a glimpse of what ...

Adjust the size and position of the text input field

I'm struggling to find a way to both resize and move the box without one action interfering with the other. Whenever I attempt to change the size of the box, it triggers the move event at the same time. Clicking on the box should make it resizable, bu ...

Is there a way to retrieve the Boolean value from an ng-show attribute without having to re-evaluate the expression?

I'm currently working on a project that involves displaying and hiding a lot of content dynamically using ng-show. Some of the expressions being evaluated are quite lengthy, like this... <div ng-show="some.object.with.nested.values && ...

Fetching large images with "fill" layout in NextJS

I am currently using Cloudinary to serve correctly sized images, however, it appears that NextJS image is always fetching with a width of 3840, instead of the fixed value. <Image src={loaderUrl(logoImage)} alt="" role="presen ...

What is the best way to align HTML inputs within a grid, whether it be done automatically or manually using JavaScript?

Arrange 20 HTML inputs with various data types into grid-columns as the user inputs data. Ensure that the grid container has div elements correctly positioned for output. ...

Loading SVGs on the fly with Vue3 and Vite

Currently, I am in the process of transitioning my Vue2/Webpack application to Vue3/Vite. Here's an example of what works in Vue2/Webpack: <div v-html="require('!!html-loader!../../assets/icons/' + this.icon + '.svg')" ...

Utilizing PHP and Ajax to showcase individual row details within a while loop upon clicking a hyperlink

In the midst of a new project, I find myself faced with a task where the user can log in and view their personal delivery orders. The list of deliveries is generated using a while loop. However, whenever I click on the details button for an item in the lis ...

Retrieve the labels associated with highlighted text in a JTextPane

Hey everyone! I'm currently working with a JTextPane that has content type 'text/html'. I have loaded the Bible into this JTextPane where verses are separated by tags. What I want to achieve is determining the selected verse when a user clic ...

What is the Vue.js alternative to setTimeout?

I'm currently in the process of developing a shopping cart feature using Laravel and Vue. In my system, when an item is added to the shopping basket, I want to display a confirmation message by toggling a Vue variable that is being monitored through a ...

Ensure that the page fully loads by using Selenium and PhantomJS during testing of an AngularJS website

After exploring many responses, it appears that the recommended solution is to use Wait for page load in Selenium. While this approach makes sense, my issue persists. I am dealing with a website built using Angular JS and facing challenges while navigating ...

Matching a regular expression pattern at the beginning of a line for grouping strings

One of my tasks involves working with a markdown string that looks like this: var str = " # Title here Some body of text ## A subtitle ##There may be no space after the title hashtags Another body of text with a Twitter #hashtag in it"; My goal ...

Is it a shallow copy or something else when updating state in React JS?

I am currently dealing with a particular state within my application: const [work, setWork] = useState([ { company: "Company", position: "President", website: "example.com", startDate: "2013-01-01", endDate: "2014-01- ...