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

The webpage fails to return to its original position after the script has been executed

My website has a sticky div that stays at the top when scrolling down, but does not return to its original position when scrolling back up. Check out this example function fixDiv() { var $div = $("#navwrap"); if ($(window).scrollTop() > $div.data("top ...

A tool designed to create a function that can fetch information from a JSON file

Currently, I am working on a function that accepts arguments and combines them to form a line for searching data in a JSON file. To accomplish this, I have initialized a variable for the readFileSync and then added the function's arguments to it in or ...

How to Keep Images Within Table Borders From Overlapping?

I am in the process of experimenting with creating a newsletter and have developed a template. I am very new to design and have created a table of album releases that is not fitting within the border I established. How can I resolve this issue? The code s ...

Uploading files to an S3 bucket with Node.js

Currently, I am utilizing Sailsjs version 0.12.1 along with node.js 4.2.6 My objective is to upload a file from the front-end (built using angular.js) through an API and then proceed to upload this file to an AWS S3 bucket from the backend. When sending ...

"Stylish footer design in CSS featuring a sleek overflow scrollbar

Perhaps the most straightforward way to demonstrate this is by providing a direct link to the website where the addition should be made. I am in desperate need of a basic footer that remains fixed at the bottom of the page, regardless of the amount of con ...

Unlocking the request object within a GraphQL resolver with Apollo-Server-Express

My express server is standard and I'm using GraphQL with it const server = express(); server.use('/graphql', bodyParser.json(), graphqlExpress({ schema })); I am wondering how to access the request object within a resolver. Specifically, ...

Chunk error ECONNREFUSED trigger

Encountered an issue while running through grunt. Getting a proxy error: Econnrefused when trying to run grunt serve. After running --verbose, it seems like the request is being blocked. I suspect it may be due to my organization's network setup, bu ...

Guide to submitting a form with an image upon pressing a button

I am working with the following HTML structure: <form id="form" enctype="multipart/form-data"> <div class="row"> <div class="col"> <div class="mb-3"> ...

What are the steps to implement Lazy loading in Node.js?

const posts = await Post.find().populate("receiver").populate("author") try { res.json({ status: true, message: 'All posts fetched', data: posts.reverse() ...

increasing the top margin on an HTML document

Looking to create a specific amount of blank space at the top of your HTML page? The space needs to be exactly X pixels tall. How can this be achieved effectively, while ensuring compatibility with Safari? ...

Having trouble setting the audio source path in a handlebars file

homepage.html <script> function playAudio(audio_src){ console.log('audio src: ' + audio_src); var player = document.getElementById('player'); player.src = audio_src; player.load(); player.play(); return f ...

Generate a JSON (Jquery) structured table matrix outlining various roles and corresponding permissions such as read, write, delete, and write special

I would like to create a table matrix that displays roles and permissions (read, write, delete, write special) using jQuery with JSON data. The table should contain checkboxes for each permission type, and the checkboxes for read, write, delete, and write ...

Tracking the movement of a handheld device through GPS technology

I am interested in creating a mobile application that can track the real-time location of users who have the app installed on their devices. The concept is to allow one or more users to follow the movement of another user using GPS on a map. I plan to deve ...

Having trouble deciding between JSON, XML, or using a database?

As I work on developing an app that involves sending an id and receiving a JSON node from PHP, I am considering the best approach for storing my data. Should I keep it as a static PHP array as shown in the code below, or should I save the data to an exte ...

Enhancing the appearance of unvisited links with background styles

I am endeavoring to incorporate an icon into all unvisited links on a specific Wordpress category page. Below is the CSS code that I am utilizing. It has been placed at the conclusion of my final CSS file. .category-xyzzy .entry-title a:link { background ...

retrieving text information as JSON data

After storing data in the database in Json format upon submission, I encountered an issue. When fetching the data from the database, the Json is retrieved as a string due to the datatype being set as TEXT. My goal is to extract specific Json objects, such ...

Can someone show me how to implement RequestPromise in TypeScript?

I recently integrated the request-promise library into my TypeScript project, but I am facing some challenges in utilizing it effectively. When attempting to use it in the following manner: import {RequestPromise} from 'request-promise'; Reque ...

Tips on crafting tailored CSS styling for targeted div elements such as before and after:

Looking to style specific div elements with the same class name? <div class="main"> <div class="banner_image"> banner 1</div> <div class="banner_image ">banner 2</div> <div class="banner_image ">banner 3</di ...

What is the best way to retrieve the file and directory tree structure from git using php?

I am looking to streamline the process of downloading zip files from my public git repository on Bitbucket. Rather than manually creating a download button for each zip file, I want to dynamically generate a PHP page that displays all available zip files a ...

Permanently dismiss Bootstrap 4 alert using a cookie

Recently, I came across a bootstrap 4 alert that I found quite useful. Here is the code snippet for it: <div class="alert alert-warning alert-dismissible fade show" role="alert"> <button type="button" class="clo ...