Creating a responsive design for mobile apps in Ionic using CSS

I need help with making my Ionic app responsive across all mobile devices. The design on the page was created using CSS, but it is not displaying properly on every device. How can I ensure that it adapts to different screen sizes?

<template>
  <IonPage>
    <ion-content :fullscreen="true" id="start" class="background">
      <div id="product_background">
        <Topbar />
        <div class="container">
          <ion-text color class="top-left">
            <h1>ARTICS PRO</h1>
          </ion-text>
           <ion-text color class="heart_icon">
            <ion-icon :icon="heartOutline"></ion-icon>
            <ion-icon :icon="shareSocial"></ion-icon>
          </ion-text>
          <ion-text color class="top-left2">
            <p>Steelseries</p>
          </ion-text>
          <ion-text color class="bottom-right">
            <p>ARTICS 7</p>
          </ion-text>


          <ion-text color class="bottom-right2">
            <p>Steelseries</p>
          </ion-text>


          <img :src="require('@/assets/headset_mockup.png')" style="height:105vw;width:100vw" />
        </div>
        <div slot="bottom" id="product_price">
        <h2>$3,9000</h2>
      </div>

      </div>
      <div id="product_info">
        <p>Product Information</p>
      </div>
      <div id="cart_icon">
         <ion-icon :icon="cart"></ion-icon>
      </div>


    </ion-content>
  </IonPage>
</template>

<script lang="ts">
import { IonContent, IonPage, IonText,IonIcon } from "@ionic/vue";
import Topbar from "../Resources/Topbar.vue";
import { useRouter } from "vue-router";
import { heartOutline,shareSocial,cart } from 'ionicons/icons';
export default {
  name: "Index",
  components: { IonContent, IonPage, Topbar, IonText,IonIcon },
  setup() {
    return {
      router: useRouter(),
      heartOutline,shareSocial,cart
    };
  },
};
</script>
<style scoped>
ion-content.background {
  --background:  url("../../assets/product_background.png") 0 0/100% 93% no-repeat;
}
#product_background {
  background-attachment: fixed;
  background-size: cover;
  padding: 20px;
}
#product_price {
  position: absolute;
  bottom: 60px;
}

.bottom-right {
  position: absolute;
  bottom: 14px;
  right: 16px;
}
.bottom-right2 {
  position: absolute;
  bottom: 0px;
  right: 16px;
}
#product_info{
  position: absolute;
  bottom: 60px;
  left: 16px;
}
#cart_icon {
  position: absolute;
  bottom: 70px;
  right: 50px;
}
#product_price{
    position: absolute;
  bottom: 150px;
  left: 20px;
}
.container {
  position: relative;
  text-align: center;
  color: white;
}
.heart_icon{
   position: absolute;
  top: 180px;
  left: 8px;
}
.top-left {
  position: absolute;
  top: 16px;
  left: 8px;
}
.top-left2 {
  position: absolute;
  top: 45px;
  left: 6px;
}
</style>

It could be because I used HTML elements instead of Ionic components. What would be the equivalent replacement for HTML tags in Ionic?

Answer №1

When working with Ionic, you have access to a grid system that allows you to create responsive HTML layouts. To achieve this, you will utilize ion-grid, ion-row, and ion-col components. The size of each ion-col can be adjusted using options like size-xs/sm/xl/lg and offset, which ensures the layout adapts according to screen size.

Imagine your screen being divided into 12 blocks, and it's up to you to determine how many blocks each ion-col should occupy.

For more information, visit https://ionicframework.com/docs/api/grid and https://ionicframework.com/docs/api/col

<ion-content>
<ion-grid>
<ion-row>
  <ion-col size-sm="6">
    <ion-item>Some content</ion-item>
  </ion-col>
  <ion-col size-sm="6">
    <ion-item>Some other content</ion-item>
  </ion-col>
</ion-row>
<ion-row>
  <ion-col>
    <ion-card size-sm="8" offset-sm="2">
      <ion-card-title>More Content</ion-card-title>
    </ion-card>
  </ion-col>
</ion-row>

</ion-grid>

</ion-content>

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

Is there a way to apply -webkit-line-clamp to this JavaScript content using CSS?

i have a random-posts script for my blogger website <div class="noop-random-posts"><script type="text/javascript"> var randarray = new Array(); var l=0; var flag; var numofpost=10; function nooprandomposts(json){ var total = ...

Ways to change content within an editable div without altering the current cursor location

In the javascript code below, I am trying to highlight characters after 255 and display them in another div with a different color. $( "#testdiv" ).keyup(function() { if($("#testdiv").text().length>255) { var text = $("#info").text() $("#te ...

Interactive Thumbnail Selection for HTML5 Video

Having trouble with creating thumbnails? I managed to solve the cross-domain issue using an html2canvas PHP proxy. No error messages in the Console, but the thumbnails are unfortunately not showing up - they appear transparent or white. Here is a snippet ...

Take away the CSS class from an element after reCAPTCHA verification is complete in Next.js

I'm struggling with removing the CSS class btn-disabled from the input button element upon successful verification of a form entry. I have implemented a function called enableForm to remove the btn-disabled CSS class when reCAPTCHA is verified. Howe ...

There was an issue encountered while attempting to add concurrently to the package.json

Bundle of scripts in package.json "scripts": { "begin": "node back-end/server.js", "serve": "nodemon back-end/server.js", "client-initiate": "npm start --prefix front-end", ...

Sorting table tbody elements created dynamically with JavaScript on an npm webpack application is not possible with jQuery UI

My JS-built table is populated with data from a JSON file fetched after a request. I want to be able to drag and drop these tbodys and update the JSON file accordingly. To handle sorting, I decided to use jquery-ui. While .sortable() works well for drag a ...

"Troubleshooting problem with padding-right in Internet Explorer when displaying background image within

Encountering a problem with the IE browser (all versions up to IE 10). Here's the issue. The text in the input box is overlapping its background image. Unable to place this image in the parent div due to the dynamic nature of the input box and other ...

Retrieve data from HTML in order to apply styling to an element

I am attempting to set the width of my .bar-1 outer span element based on the value of my inner span element. <span class="bar bar-1"> <span name="PERCENTAGE" id="PERCENTAGE" disabled="" title="Total Percentage" maxlength="255" value="66" tabinde ...

How can a controller configure an AngularJS provider by passing options?

How can I pass configuration options to a provider from a controller? Below is an example of how to pass options/configurations to a provider from the controller: provider.js file: app.provider('contactProvider', function() { this.name ...

Tips on incorporating the $ symbol into a pseudo element

Can I add a price using a pseudo element? h3:after{ content: " (+ $75)"; } <h3>price</h3> The CSS minifier is preventing the display of "$75". How can I work around this issue? ...

Manipulate your table data with jQuery: add, update, delete, and display information with ease

When adding data dynamically to the table and attempting to edit, the checkbox value is not updating. This issue needs to be resolved. You can view the code in action on jsFiddle here on JSFiddle ...

"Sequencing time with Postgres, manipulating views with Angular

I am encountering issues with displaying graphs in AngularJS. My backend is written in nodeJS and includes an aggregator as a buffer for data received from netdata, which is then inserted into the database using a cron job. Now, with a new client request, ...

Tips on displaying a div for a brief moment and then concealing it

Is it possible to create a div that will disappear after 10 seconds of the page loading using PHP or JavaScript? Here is an example of the code: <html> <head></head> <body> <div class="LOADING" id="LOADING" name="LOADING">&l ...

Error: The specified function in the schema is not valid for the current operation mode

I'm facing an issue with validating a material ui form using Formik and Yup. The error keeps popping up. This is the schema I imported from another file: export const validationSchema = Yup.object({ email: Yup.string() .email('Invalid Ema ...

The issue of execution order in JavaScript Recursion with promises

In the process of developing a method for creating markup to be used in a web app's off-canvas navigation. One of the challenges I am facing is making an asynchronous callback to another service that provides children nodes for the parent menu node (r ...

How can I show the table row as an inner table row when the first field is identical?

<tr ng-model="check" ng-repeat="orderBook in orderBookDetails| orderBy: 'orderBook.no'" value='check=$scope.orderBookDetails.sowNo'> <td ng-if='check!=orderBook.no'>{{orderBook.no}}</td> <td>{{order ...

Problem arises when attempting to display a div after clicking on a hyperlink

I'm encountering an issue with displaying a div after clicking on a link. Upon clicking one of the links within the initial div, a new div is supposed to appear below it. All tests conducted in jsfiddle have shown successful results, but upon transf ...

disallow rowOnClick function in the datatable

I am facing an issue with a t:datatable where the rowOnClick event is being triggered. The problem arises when there is an icon in a column that, when clicked, opens a popup. This action also triggers the rowOnClick event, which I don't want. For this ...

Having trouble accessing portlet resource URL from JavaScript in Liferay 6.2

I have been working with Liferay Portal 6.2 CE GA3 and I am facing an issue where I need to execute a custom portlet resource method from another portlet's JSP file. Below is the code snippet I am currently using. <a href ="#" onclick="myfunctio ...

Applying onclick css changes to a specific duplicate div among several others?

Recently, I encountered a situation where I have multiple identical divs on a page. <div class="class" ng-click="example()"></div> With the use of Angular 1.6.4 and jQuery, these divs are styled with background color and border color. Now, w ...