Dynamic styling based on the bottom property

I need to adjust the bottom property value in my mat-select-panel by using the following CSS code:

::ng-deep .cdk-overlay-pane {
    bottom: 0px !important;
}

However, I would like this CSS to only be applied when the bottom property is negative.

Is there a simple method to achieve this?

Answer №1

Consider trying out a similar approach for your solution:

CSS:

::ng-deep .overlay-style-one cdk-overlay-pane {
  bottom: 0px !important;
}

::ng-deep .overlay-style-two cdk-overlay-pane {
  bottom: 10px !important;
}

HTML:

<mat-form-field>
   <mat-select #myselect
      [ngClass]="{ 
         'overlay-style-one': myselect.style.bottom = "100px",
         'overlay-style-two': myselect.style.bottom < 0,
      }"
   >
      <mat-option>-- EXAMPLE --</mat-option>
      <mat-option value="YES">
         Yes
      </mat-option>
      <mat-option value="NO">
          No
      </mat-option>

   </mat-select>
</mat-form-field>

In case you encounter issues with fetching the bottom property using (#local reference), alternative options could be vrender2 or employing an id="XXX" for the matSelect and accessing properties in traditional JavaScript manner:

  [ngClass]="{ 
         'overlay-style-one': document.getElementById("XXX").style.bottom < 0,
         'overlay-style-two': document.getElementById("XXX").style.bottom >= 0,
      }"


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

Array containing multiple service providers in Angular

I encountered a problem while utilizing multiple providers in my application: ERROR Error: No provider for Array! at injectionError (VM634 core.umd.js:1238) [angular] at noProviderError (VM634 core.umd.js:1276) [angular] at ReflectiveInjector_._throwOrNul ...

How you can incorporate an icon in between menu items using Bootstrap 4

As a novice web developer, I am currently utilizing Bootstrap 4 in my project. Here is the code snippet I have created: .footer-menu a{ color: #2D2D2D; font-size: 1em; } .copyright{ color: #D1D1D1; font-size: 0.9em; } <footer> ...

Guide to declaring variables using jQuery

Currently tackling a school project, I stumbled upon some online example solutions and managed to decipher most of the code. However, there is one line that has me puzzled. var $newTweet = $('<div class=tweet></div>'); My assumption ...

Angular Material Stepper Design Styling Guide

https://i.sstatic.net/8R93n.pnghttps://i.sstatic.net/VxzP3.png Hello, I am interested in customizing the angular material stepper UI similar to the image provided. I would like to know if it is possible to programmatically change the icon. In case of an e ...

Tips for creating a table that fills the height of its parent div without surpassing it

Issue: I am facing a challenge with making a <table> element fill 100% of its container's height dynamically, without going over the limit. Context: When the height of the <table> surpasses that of the container, I want the ability to s ...

Adjust the max-height to occupy the entire available space

One of the challenges I'm facing with my web application is designing the layout in a way that all elements interact seamlessly. The structure is as follows: <body> <nav> <-- top navigation bar <ol> <-- breadc ...

Ensure that the height of the bootstrap image is limited by the dimensions of another column while still preserving its

I need to develop a versatile element with bootstrap that can accommodate images of different aspect ratios. To achieve this, I must trim the right side of the picture like so. <div class="container"> <div class="row"> <div class="col-12" ...

Establishing fixed values in an angular2 component

Is it possible in angular 2 to initialize values within the HTML view of a component that has already been rendered in PHP? //html page: <dropdown [(options)]="['Available', 'Busy', 'Away', 'Offline']"></dr ...

Expand the Layer if it overflows

Currently, I have a div element containing various content with Java dropdown links causing the length of the content to vary greatly vertically. By applying "overflow-y: scroll," the content remains in the layer and a scrollbar appears, functioning as in ...

Tips for creating a section that perfectly stretches to cover the entire view port in HTML

After browsing through this website, I was inspired by its design and wanted to replicate something similar. The unique approach they took to ensure each section fits 100% of the viewport caught my eye. They utilized a "div section-background" within each ...

Incorporating various elements within a single column of a table

I have been attempting to include multiple table cells elements beneath each of my heading cells, but I am facing issues in getting it to work properly. For better understanding, this is a screenshot: https://i.sstatic.net/kg2XR.png My goal is to have o ...

When the maximum height reaches 100%, it surpasses the limit set by the viewport height

I'm looking to create a fixed footer at the bottom of my page, where the contents adjust based on the view height. Recommended: Check out this CodePen for an example with a well-contained layout. You'll notice that even as the menu items increas ...

The Ionic view is not reflecting updates in real-time when there are changes to the component properties

Having an issue with updating stock data on the view in my ionic 3 project. I am able to see frequent updates in my component and console, but these changes are not reflected on the view as frequently. For every 10 updates in the component, only 1 update i ...

I am looking to have two elements positioned next to each other in equal dimensions, such as the reCaptcha feature

Could someone assist me in positioning these elements side by side, each taking up 50% of the screen? I'm unsure if this can be achieved while using the reCaptcha iFrame. <div class="g-recaptcha" data-sitekey="sitekey" style="transform:scale(0.5); ...

Floating multiple block-level elements within an <li> tag in HTML allows for greater control over the layout and

I am facing a complex issue that requires attention. Let me explain the situation: There is an unordered list consisting of list items displayed vertically with alternating background colors, all having the same width within a fixed-width div. Some list i ...

What steps should I follow to create a photo gallery similar to Facebook?

I am currently developing a 4x3 image gallery showcasing pictures sourced from a database. Each picture varies in size. Utilizing Bootstrap and CodeIgniter, I create rows and columns for each image. My goal is to ensure that wide images adjust to the heigh ...

Disable the spinning animation of the Bootstrap spinner to keep it still and static

I am currently utilizing bootstrap 4 for my project. When a particular event starts, I have successfully managed to make the spinner spin with the code snippet below: <span class='spinner-border spinner-border-sm text-primary' role='statu ...

Caution: The `className` property does not align with Material UI css which may cause issues upon reload

https://i.stack.imgur.com/MxAiY.png If you are facing the error/missing CSS, check out this video for a visual representation. While older versions of similar questions exist on Stack Overflow such as React + Material-UI - Warning: Prop className did not ...

Tips for aligning elements of varying sizes seamlessly with CSS grid?

I am currently working on creating a CSS grid layout. The issue I'm facing is that the first element has a fixed height, causing the entire first row to have the same height. I want the elements in the second row to move up and fill the empty space in ...

The onClick event in HostListener is intermittent in its functionality

While attempting to create a dropdown box in Angular by following these examples, I am encountering inconsistent results. Below is the code I have used: HTML <button (click)="eqLocationDrop()" id="eqLocButton"><i class="fas fa-caret-down">< ...