What is the best way to display two items side by side from a list of items in HTML?

I have a list of items that are displayed in `webView` with 4 elements per row. However, for `mobileView`, I would like to show only 2 elements in each row. Below is an example from my HTML file:

<div class="row my-3 cust-heading" style="margin-left: 39vh; margin-right: 39vh;">
    <div class="col-md-3 my-4 products" ng-repeat="product in productList track by $index" ng-if="$index<12">
        <div class="productList">
            <img class="product-image mb-2" src="{{product.imageLink}}" />
            <h6 class="product-name" style="font-size: 14px;">
                <b>{{product.productName}}</b>
            </h6>
            ...
        </div>
    </div>
</div>

This CSS media query adjusts styling for mobile devices:

@media (max-width: 425px) {
    .header-img {
        background-image: url('/img/bg-mobile-new.jpeg') !important;
    }
    ...
}

Here is how it looks on `webView`:

https://i.sstatic.net/kjWT7.png

And here is the display on mobile:

https://i.sstatic.net/p7chM.png

To adjust the layout for `mobileView` and display 2 items per row, some modifications need to be made in the code. What steps should I take to achieve this?

Answer №1

<div class="col-md-3 ...etc

Sets the width (at medium res.) to 3 out of 12 columns = 4

You can default it to 2 columns at lower resolutions by using this:

<div class="col-6 col-md-3 ...etc

Consider changing 'productlist' to 'product,' since the loop surrounds the 'list' now

Also, remove on the row:

margin-left: 39vh; margin-right: 39vh;

If you want to center the page, use a

<div class="container">...</div>

Around the row

Check:grid system bootstrap

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

Angular mobile navbar experiencing collapse issue

I am working on an Angular project that does not include Jquery. I am trying to implement a navbar using mdbootstrap, but I am encountering issues with the collapse feature not working properly. Below is the HTML content I am using: <header> < ...

Creating a custom dynamic favicon and title in NextJS

Hello there! I am in the process of creating a web constructor. Currently, my application functions as follows: I verify the URL that the user is visiting (such as localhost:3000) I identify their project name within my web constructor (localhost:3000 -&g ...

Retain values of JavaScript variables acquired by their IDs even after a page refresh

I have a JavaScript function that retrieves HTML input values and inserts them into a table. However, when I refresh the page, those values are reset to null. How can I prevent this and keep the values visible after a refresh? I believe setting and getting ...

The textbox is not able to process the complete input string provided

I am having trouble with entering an email address into a textbox, for example [email protected], as it only accepts dd@g. Here is the HTML code: <input type="email" class="form-control ng-pristine ng-valid-email ng-invalid ng-invalid-required ng ...

What is the best way to showcase saved HTML content within an HTML page?

I have some HTML data that was saved from a text editor, <p style=\"font-size: 14px;text-align: justify;\"> <a href=\"https://www.xpertdox.com/disease-description/Chronic%20Kidney%20Disease\" style=\"background-color: tr ...

Modifying JavaScript Code in Inspect Element Editor

When I modify the HTML content using Chrome's Inspect Element editor, any changes made are immediately visible. However, when I make changes to the JavaScript code, the modifications do not take effect. For example, if I have a button that triggers a ...

Encountering a problem creating a hover overlay effect on a transparent PNG image within a parent div that has a background color

I'm struggling with creating an overlay hover effect on an image that has transparency. The issue I'm facing is that the black background of the parent div element is filling in the transparent parts of the PNG image, making it look like those ar ...

In Chrome, CSS automatic hyphens are displayed as question mark symbols

On my website, I have implemented automatic hyphenation using CSS: article > p, article > li { -o-hyphens: auto; -o-hyphenate-limit-before: 3; -o-hyphenate-limit-after: 3; -o-hyphenate-limit-chars: 6 3 3; -o-hyphenate-limit-lines: 2; -o-h ...

In Chrome, there is a single pixel missing below the <dl> element

While my website's basic list looks great on Firefox and IE, there seems to be one missing pixel line in Chrome. Check out this JsFiddle link shared by Jared in the comments for reference. If you're not seeing the missing line, try adjusting th ...

Using the fieldset element in AngularJS Material causes disruptions in my flex layout

My current issue can be illustrated through two code examples: The first example functions properly when the fieldset is not included. In the second example, including the fieldset causes the layout to extend beyond the window when there is long text (in ...

JavaScript error occurring when trying to validate Ajax response

I am attempting to create a report using a dynamically generated form. The form loads successfully through XMLHttpRequest, but the validation for the form fields does not seem to be working. I have experimented with using eval() and found that it only work ...

What's the deal with inline blocks and text in the middle?

Check out this code I created for a navigation bar. HTML : <div class="header-nav"> <div class="header"> <img src="../Pictures/LifeFrame/2.jpg" width="100%" height="100px" /> </div> <div class="nav" align="c ...

Tips for utilizing ng-model in an Angular application

<input type="search" placeholder="{{'COMPONENT_PROPERTIES.SEARCH_ICON' | translate}}" ng-model="icon.name" list="classIcon" ng-change="changeFn(icon.name)"> <i class="{{$select.selected}}"></i> &nbsp;&nbsp; {{$s ...

The removal of classList.remove() only eliminates the class itself, not its contents

My goal is to add one class and remove another class when the start quiz button is clicked. While the 'info_box' class is successfully added, the 'start_btn' class does not get removed; it just changes position (from flex to no flex). T ...

Transferring information from user input to a table using AngularJS

I need assistance with AngularJS to transfer data from 2 input fields (name and last name) into a table row. <input type="text" ng-model="name"> <input type="text" ng-model="lastname"> Here is the structure of my table: <tabl ...

Picture not showing up when loading iPhone video

My website features a video that is displayed using the following code: <div class="gl-bot-left"> <video controls=""> <source src="https://www.sustainablewestonma.org/wp-content/uploads/2019/09/video.fixgasleaks.mp4" ...

Incorporating a CSS Stylesheet into an ASP.NET Custom Control

Currently, I am in the process of developing a unique custom control that consists of a combination of tables and buttons. Alongside this, there is an external CSS stylesheet that defines the styles for these specific elements. This control falls under th ...

embedding a button alongside the pager in an HTML document

I am encountering an issue with the positioning of a button in my paginated table setup. The button is currently displaying below the pager instead of being aligned on the left side of the page along with the pager. https://i.stack.imgur.com/gUiB9.png To ...

Identify the fields in the form that have been edited for easier reference

Seeking guidance on creating a form with interactive input box fields. When a user inputs something, the field highlights in orange. Moving to another field removes the highlight and focuses the new box. Clicking "save" stores the form data. Pressing "mo ...

The text alongside the radio button is not aligned vertically

Hello, I am attempting to vertically align text next to my radio button but encountering some issues. .radio { cursor: pointer; display: inline-flex; } .cui-a-radio-button__input { display: none; } .cui-a-radio-button__input:disabled + .cui-a-rad ...