Attempting to determine the smallest and largest dimensions of two values using CSS3

Trying to make sure the image on my phone adjusts its size based on orientation, I attempted using Ionic4. When in landscape mode, I want it to adapt according to height instead of width. Essentially, I need it to use the minimum size and also require the opposite functionality for another area (maximum).

My initial approach was using the min() and max() functions; however, they seemed to not work. Upon further investigation, it appears that these functions have been deprecated. I'm open to exploring alternative methods if available.

.heart-style {
 position: absolute;
 right: 0;
 top: 0;
 width: min(10vw, 10vh);
 height: min(10vw, 10vh);
}

.welcome-card ion-img {
 height: max(30vh, 30vw);
 object-fit: cover;
}

This is the error message when attempting to use min() or max() functions:


Compilation failed.

./src/app/home/home.page.scss Module build failed (from ./node_modules/sass-loader/lib/loader.js): Incompatible units: 'vh' and 'vw'.


I also experimented with different units, but encountered the same issue.

Answer №1

To determine if you are in landscape (viewport width is greater than height) or portrait mode (viewport width is equal or less than height), you can utilize @media (orientation: ...) media queries.

.heart-style {
  position: absolute;
  right: 0;
  top: 0;
  width:10vw;
  height:10vw;
}

.welcome-card ion-img {
  height: 30vh;
  object-fit: cover;
}

@media (orientation: landscape) {
  /* Adjust dimensions for landscape orientation */
  .heart-style {
    width: 10vh;
    height: 10vh;
  }

  .welcome-card ion-img {
    height: 30vw;
  }
}

/* Debugging styles */
.heart-style {
  background: blue;
}
.welcome-card ion-img {
  display: block;
  background: yellow;
}
<div class="heart-style">
  heart
</div>

<div class="welcome-card">
  <ion-img>
    img
  </ion-img>
</div>

Answer №2

A more efficient method for installing the ionic plugin ionic-native/screen-orientation provides the ability to detect screen orientation within JS code and offers various other features as well.

import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';

constructor(private screenOrientation: ScreenOrientation) { }

...

// get current
console.log(this.screenOrientation.type); // logs the current orientation, example: 'landscape'

For more information, visit the official URL native/screen-orientation

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

PHP mistakenly outputs content that is not enclosed within tags

After discovering StackOverflow, I couldn't resist sharing my PHP code conundrum with the incredible community here! So, in a WordPress template, I have this chunk of PHP: echo '<div class="thumbnail">'; echo the_post_thumbnail(); ec ...

Utilize Ionic Auth Connect to establish the currentSession and currentAuthenticatedUser on AWS Amplify

Problem with Amplify Configuration In the process of developing a new ionic app, our team decided to utilize AWS Amplify as our backend solution. To interact effectively with various services, we opted to use both "AMAZON_COGNITO_USER_POOLS" and "API_KEY" ...

The show more/show less link for a long jQuery paragraph is malfunctioning

I encountered an issue while coding where the "read more" link works correctly, but the "show less" link does not. Despite my efforts, I cannot seem to identify the error. Within this code snippet, there is an anchor tag with class="show-less" that I am u ...

Guide to incorporating navigation buttons (back and forward) in a modal box

I have successfully created image thumbnails and linked them using the provided code. <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script> <script src="https://maxcdn.bootstra ...

Mobile version shows white spaces when using particles.js and bootstrap 4.6

This is how I implement particles.js: <div id="particles-js"></div> @RenderSection("Header", required: false) <main role="main" class="container"> @RenderBody() </main> <script> ...

Exploring the world of CSS: accessing style attributes using JavaScript

So I created a basic HTML file with a div and linked it to a CSS file for styling: HTML : <html> <head> <title>Simple Movement</title> <meta charset="UTF-8"> <link rel="stylesheet" type=&qu ...

Customize the overlay color using the theme's background color

I want to create an overlay on my webpage that covers all the content. However, I'm facing a challenge because my website allows users to customize the theme colors, and the overlay div does not adopt these color changes automatically. To rectify this ...

Is there a way to eliminate the shadow effect appearing on product photos in BIG CARTEL?

While using the Luna theme on my Big Cartel store, I noticed that the products are hard to see on mobile devices because of the box shadow effect. I found a solution on a Big Cartel help page recommending to add a specific code to the CSS, but when I tried ...

How can a new <li> element be created without being influenced by certain CSS styles?

I am attempting to enhance my menubar by adding a signup/login item aligned on the right without affecting the other center-aligned items. Essentially, I have an entry named "Login/Sign Up" that should maintain its own unique style while seamlessly blendin ...

"Enhance your browsing experience with Chrome by automatically changing the background when

I am currently using Chrome with a CSS3 background. <h4 class="title-name clearfix"><a href="****************">Fairy Tail - LUCY</a> </h4> My issue is that when I hover my mouse over the title, the ba ...

Tips for employing Flex-grow alongside the behavior of "justify-content: start"

I am working with a flex container setup like this: .container { display: flex; flex-flow: row wrap; justify-content: start; width: 100%; } .item { border: 1px solid red; flex: 1 1 33%; height: 100px; } <div class="container"> <d ...

I encountered a difficulty in getting my video to play properly on the Safari browser

I am trying to figure out why my video won't play on Safari, even though it works fine on Google Chrome and Edge. Below is a snippet of my HTML code: <video width="640" height="360" controls="true" autoplay loop muted ...

What is the best way to comprehend IE comments in a given condition?

I recently came across some conditional comments in a theme I'm working on that dynamically add classes to the html tag depending on the version of Internet Explorer being used. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" ...

I'm struggling with organizing my webpage layout using CSS flexbox and CSS grid

Currently, I am working on creating a checkers game using HTML and CSS with the inclusion of CSS Flexbox and CSS Grid for layout design. However, I have encountered an issue where the page is not responsive vertically. When resizing the browser height in C ...

Do CSS Modules consistently generate the same class name for a specific CSS class defined within the module?

I have defined the following classes in my CSS module: .container-styles { height: 20px; width: 90%; background-color: rgb(128 , 128 , 128); } .filler-styles { height: 100%; border-radius: inherit; background-color: rgb(27, 150, 40); text-al ...

Container filled with a table element

My challenge involves a container grid with 3 div flex subelements. The first is the fixed header, the second is the body, and the third is the fixed footer. Within the body, there is a table. What I want to achieve is that when I resize the window, the ta ...

How can I ensure that my data remains properly aligned in a row with 9 columns while utilizing bootstrap?

My approach to creating a row with 9 columns involved using custom CSS to set each column's width to 11.11%, resulting in equal distribution across the row. I then applied the "custom-column" class to populate the row data: .custom-column { widt ...

"Unexpected behavior: datatables.net plugin causing left menu to be hidden behind table in Internet

My webpage was functioning perfectly in Internet Explorer. I decided to enhance it by incorporating the impressive jQuery plugin Datatables. I added the following code in DOMReady: $('#articlestable-container table').dataTable({ "bPaginate ...

Tips for personalizing the streamlit expander widget

After diving into the streamlit components documentation, it became clear that rendering HTML code for the label parameter of the st.expander() function is not supported. Is there a way to work around this limitation? My exact requirement is as follows: ...

Enhancing Image Quality in Microsoft Edge

I'm trying to figure out how to make an image scale with bicubic in MS Edge. Is there a CSS solution or something similar that can change this behavior? Check out this page: On the right side of the page, there are two images with textured backgroun ...