Tips for arranging items within a div in 2-3 rows on mobile devices (responsive design)

My website has a div that displays the categories, but it's too long on mobile and messes up the screen width. I want to turn this div into 2 or even 3 rows when viewed on mobile devices. The challenge is that the elements inside the div are dynamic, so I'm not sure how to align them in multiple rows at specific points since it's all dynamic...

This is my current HTML structure:

<div class="categories-container">
    <mat-button-toggle-group #group="matButtonToggleGroup" name="fontStyle" aria-label="Font Style" value={{selectedCategory}}>
        <mat-button-toggle class="categories" *ngFor="let category of categories; let i = index" (click)="selectedChanged(group.value)" value="{{category._id}}">{{category.name}}</mat-button-toggle>
    </mat-button-toggle-group>
</div>

And here is my CSS:

.categories-container {
    position: absolute;
    bottom: 300px;
    left: 680px;
}

@media screen and (max-width: 768px) {
    .categories-container {
        position: static;
        width: 100%;
        height: 100px;
        padding-top: 5px;
    }
}

Note: Adjusting the width did not solve the issue.

Here are some photos for clarification:

Current display on mobile: https://ibb.co/0JCVDfY

Desired layout: https://ibb.co/DGSmnF2

Answer №1

To achieve a scrollable effect for the .categories-container, you can apply overflow:auto

Answer №2

example can be found in this stackblitz demonstration

All you have to do is define the property for the mat-button-toggle-group class.

mat-button-toggle-group {
   flex-wrap: wrap;
}

This adjustment ensures that the list flows row by row based on available width.

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

Tips for opening local HTML files on iPhones and Android devices

Is there a way to access local files on my PC from my iPhone and Android devices without having to upload them to an FTP server each time? I currently use Windows 7 with an iPhone 4 and an Android device. When I need to view a file on my iPhone's brow ...

The hyperlinks lead to pages that are not related to the topic at

My goal was to make links interactive using JQUERY when they are clicked. After some research, I discovered a code snippet on stackoverflow that seemed to work well. However, when I clicked on the links, they would become bold or active as intended, but t ...

Storing the chosen item in a PHP drop-down menu

Is there a way to keep the selected value of a drop down when submitting a form with an onchange event? This is my current code: echo "<form method=\"post\"> <select name=\"Color\" OnChange=\"this.form.submit();\"&g ...

How to align the "bootstrap navbar li items" in the center across all page widths

I'm trying to center the li items "on the entire page width" in this basic bootstrap navbar that I've shared. I attempted using "justify-content-center" in the parent. It did center the navbar items, but not across the entire page width. The ite ...

Tips for creating a seamless horizontal scrolling effect in Angular when hovering (automatically)

One of the components I'm working on features a gallery with an X axis orientation. <div class="gallery"> <div (mouseenter)="scrollTo('left', $event)" (mouseleave)="clearIntervalRepeater()" class="left"></div> < ...

Unnecessary list elements generated by dazzling navbarPage

While developing an app with shiny using navbarPage, I noticed that there are some unwanted li tags in the HTML that are not defined in my code. Could this be a known bug? How can I go about fixing it? <nav class="navbar navbar-default navbar-stati ...

What are some effective ways to prevent a sidebar layout from scrolling in bootstrap?

I'm working on creating a simple admin panel and have set up a sidebar layout. My goal is to keep the sidebar fixed so that it doesn't scroll when I scroll down the page. Initially, it looks like this: https://i.sstatic.net/dcFX3.png However, a ...

Accessing a defined type from a variable in an Angular project using Typescript

interface Bus { id: number; test?: string; } interface Area{ id: number; load?: string; } type TypeMap= { Bus: Bus, Area: Area, // etc } func1(){ const vehicleType1 = "Bus" const vehicleType2 = this.getSelectedVehicl ...

Chrome is the only browser displaying background images

My current issue is that the background image only appears on Chrome and not on Firefox or Edge. I am trying to have a different background image each time the page loads. $(document).ready(function() { var totalBGs = 5; var rnd = Math.floor(Math.ran ...

When the boolean in RxJS skipWhile remains true

My current scenario involves a specific use-case: There is a service that queues calculation tasks assigned with a certain ID. I have set up an observable to monitor the status of the service. When the ID is still in the queue, the query result is true (i ...

Using Jquery to select and apply functions to specified div elements

As someone who is relatively new to JQuery, I have a question regarding the .on() function. Take this example: $('div').on('click', function() {$(this).toggleClass('show-description');}); This code selects all the 'div& ...

What is the best way to ensure the font size is responsive in Laravel's welcome.blaze.php file?

On a large screen, the word "LaravelProject" and its links have ample space which I prefer. https://i.sstatic.net/AcnQ3.png A newly created Laravel project appears differently on a small screen. https://i.sstatic.net/O4fBq.j ...

Issue with Angular 8 docker container: module not found despite being installed

I am currently working on an Angular 8 single-page application (SPA). Utilizing a Dockerfile that is managed and executed through a Docker Compose setup. Everything was functioning smoothly for weeks until today when, out of nowhere, the setup stopped wor ...

Is it possible to override the body width setting?

Is it possible to override the width of the body element? For example, consider the following: <body> <table id="table1"> <tr><td></td></tr> </table> <table id="table2"> <tr><td></td>& ...

What is the best way to customize the color and width of div elements on a webpage?

I am trying to customize the colors and widths of multiple div elements using arrays and a for loop in my HTML code. However, I am having trouble figuring out how to properly implement this. Specifically, I want 5 divs on the page with different background ...

Tips on effectively deploying Angular Universal to a production server

After setting up my website by customizing the universal-starter seed from this library: https://github.com/angular/universal-starter, I have successfully rendered HTML on the localhost node server. Now, with an SSH connection and Node.js installed, I find ...

Tips for eliminating white spaces when text wraps onto a new line

Imagine having the following code snippet. Essentially, I have a layout that needs to display 'vs prev period' with a percentage in the same line. To achieve this, I utilized display: flex. The issue arises when we require the gap between the tw ...

I can't figure out why this Angular code for an Ionic alert isn't functioning properly

async displayNotification() { const notification = await this.notificationController.create({ header: 'Notification', subHeader: 'Additional Info', message: 'This is a notification message.', button ...

Exploring Angular 11: Transforming a form control into a nested form array within another form array

I am working on an array form that includes the following controls: this.formBuilder.group({ fieldName: [null, Validators.required], displayName: [null, Validators.required], fieldType: [0, Validators.required], defaultValue: [null], fi ...

Unable to connect the CSS file from the JSP during a Cross Domain request in Internet Explorer 9

I have created a GWTP web application and am making AJAX calls to a JSP page on a different domain (Cross domain) from the GWT client side. Most of the time, the CSS files are linking correctly and working fine. However, occasionally they do not link prop ...