Ionic - Landscape Mode Causing Alignment Distortion

I'm currently working on designing a grid-based image display for an Ionic Mobile App. One of the main challenges I'm facing is adjusting the heights of the images based on the screen size. I want to set a maximum height for both portrait and landscape modes. How can I accomplish this?

Here are some specifics: The grid looks correct in Portrait Mode (see Image Below) https://i.stack.imgur.com/8hux4.png

However, when switching to Landscape Mode, the height gets distorted with one card overlapping another (refer to Picture Below) https://i.stack.imgur.com/RaVfk.png

To address this issue, I increased the original height of the cards from 107px to 157px, which helped improve the appearance in Landscape mode (see Image Below) https://i.stack.imgur.com/Zb3NC.png

Unfortunately, increasing the height also affected the layout in portrait mode as it introduced spaces between rows due to the fixed size of each image (see Image Below)

https://i.stack.imgur.com/qoIzF.png

HTML
 <ion-nav-view>
    <ion-content>
      <div style="margin-top: 5px;">
        <div class="col col-50 cards" ng-repeat="list in lists" ng-style="{ 'background-image': 'url({{list.imageURL}})'} ">
        </div>
      </div>
    </ion-content>
  </ion-nav-view>


CSS
.cards{
      position: relative;
      width: 96%;
      background-size: 100%;
      background-repeat: no-repeat;
      padding: 0 px;
      float: left;
      height: 107px; // This works in Portrait Mode          
       }

Answer №1

My solution involved utilizing a media query to address the issue:

@media only screen
 and (min-device-width: 401px)
 and (max-device-width: 736px){

 .cards{
  height: 157px;
 }
}
}
.cards{
  position: relative;
  width: 100%;
  background-size: 100%;
  background-repeat: no-repeat;
  padding: 0 px;
  float: left;
  min-height: 107px;        
   }

Answer №2

Consider implementing this solution for handling orientation changes.

function adjustHeightOnOrientationChange()
  {
    switch(window.orientation) 
    {  
      case -90:
      case 90:
        // landscape view
        // add class plus_height to increase height by +157px of the card element
        angular.element(document.getElementById('card')).addClass('plus_height');
        break; 
      default:
        // portrait view
        // add class remove_height to decrease height by -157px of the card element
        angular.element(document.getElementById('card')).removeClass('remove_height');
        break; 
    }
  }

  window.addEventListener('orientationchange', adjustHeightOnOrientationChange);

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

Hiding the last row of floated elements only if it is not an even row can be achieved using CSS

I am trying to find a quick and easy solution (either using CSS or jQuery) to hide the last row of floated elements if they are not even. Take a look at this JS Fiddle example: http://jsfiddle.net/cohhvfjn/ There is an issue when resizing the HTML contai ...

New alternative for form-control-feedback in Bootstrap 4

The form-control-feedback class doesn't appear to be included in Bootstrap 4. What is the most effective way to achieve the desired outcome (an icon inside the textbox) using Bootstrap 4? <head> <link rel="stylesheet" href="https://max ...

decorating elements in a line with colored backgrounds

I am facing an issue where I want to keep three divs aligned horizontally on the same line, but their background colors are causing them to not align properly. Adding margin or padding causes the divs to wrap up instead of staying in line. #service_cont ...

The Capacitor Community Electron Platform, which combines IONIC, Angular, and Electron, encountered a TypeError: [ERR_INVALID_ARG_TYPE]. This error message indicates that the "path" argument must be in the

I have been attempting to follow the guidelines provided on to integrate the Capacitor Community Electron into a brand new Ionic Angular Test App. Everything is going smoothly until I reach the step where I need to add the platform as per the instructions ...

How can I include multiple search forms on a single page in TYPO3 Ke_Search without any conflicts between them?

In the header of my website, I have a search form that is generated as a cObject from a content element containing a ke_search searchbox. When this form is submitted, it redirects to a /search page. In addition to this, I have subpages that are meant to se ...

Show information from JSON based on the provided parameter

I'm trying to display JSON data based on a parameter passed through state params. However, when using the underscore library, the array is not showing anything. I need help checking the controller code for any issues or if there's an alternative ...

How to turn off and on all elements within a Div tag

Is there a way to disable all elements within a Div tag? I've managed to disable input types successfully, but I'm struggling with links. I attempted the solution provided here, but it didn't work. Here's the code snippet that worked f ...

Implementing bootstrap columns while displaying individual components one after the other

Here is the html code I am currently working with: <label>Search:</label> <input type="text" id="list_search" class="form-control col-8"> <button class="btn btn-info col-2">Search</button> It's interesting to note that ...

The image fails to appear

Check out my website at www.wostokhr.pl I am having trouble getting the picture "pics/hero.jpg" to show up in the "div id="hero"" section with a JS parallax function. I have double-checked the HTML and CSS validators and everything seems to be correct. An ...

Bring the element into view by scrolling horizontally

I am facing a challenge with a list of floated left divs inside another div. This inner block of divs can be hovered over to move it left and right. Each inner div, known as 'events', has class names that include a specific year. Additionally, t ...

Steps for arranging text in a dropdown list option

How can I format 3 words in a dropdownlist option so they are aligned properly? eg. <option value="1">ABCDE - ALPHA</option <option value="2">1234 - NUMERIC</option> <option value="3">ABC123 - ALPHANUMERIC</option> I woul ...

Discover the power of utilizing JavaScript to sort through table rows by filtering them based on the selections of multiple checkbox

How can I create interdependent logic for checkbox sections in a form to filter based on all selections? I am looking for help with my code snippet that showcases checkboxes controlling the visibility of table rows: $(document).ready(function() { $(" ...

Is there a way to horizontally center a content container in Flutter similar to a "max-width" container in CSS?

How can I create a centered content box like this in Flutter?: .content-box { margin-left: auto; margin-right: auto; width: 100%; max-width: 600px; background-color: blue; height: 100vh; } <div class="content-box"> Cont ...

Guide to Implementing h-100 Class in Bootstrap 4

I am facing an issue with the height of the sidebar in my admin panel. Despite trying to set the sidebar's height to 100%, I have been unsuccessful in solving this problem. <html class="h-100"> <head> <title>Admin</title> ...

What is the best way to enhance the class following this condition in JavaScript?

Initially, the original script worked perfectly with just one class being added: function check_btn_charge() { if (parseInt(jQuery(".total-change-price").text()) >= 0) { jQuery(".btn-action-save-charge"+"&nbsp;"+"btn-danger" ...

How can validation of input fields be implemented in React Js?

Currently, I am dealing with a variable (in my actual application it is an API) named data, which contains nested items. Starting from the first level, it includes a title that is already displayed and then an array called sublevel, which comprises multip ...

jQuery: Automatically scroll to the end of the div based on the height of the content within

I have successfully developed a chat feature that is functioning perfectly. However, I am encountering an issue with making my div scroll to the bottom. The height of the div is calculated as calc(100% - 60px);. This particular div retrieves messages from ...

Comparing the Calculation of CSS Selector Specificity: Class versus Elements [archived]

Closed. This question requires additional information for debugging purposes. It is not currently accepting answers. ...

Attempt to create a truncated text that spans two lines, with the truncation occurring at the beginning of the text

How can I truncate text on two lines with truncation at the beginning of the text? I want it to appear like this: ... to long for this div I haven't been able to find a solution. Does anyone have any suggestions? Thanks in advance! ...

What is the best way to add two hyperlinks within a single tab of a Bootstrap navigation menu?

I attempted to place two links in one tab, but I was unsuccessful. Here is my navbar code: <!DOCTYPE html> <html lang="eng"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scal ...