applied CSS rule for opacity is different from the computed styles

245 views Asked by At

I'm inspecting https://ionicframework.com/docs/api/alert alert..

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Alert</title>
  <script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"></script>
  <script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css"/>
  <style>
    :root {
      --ion-safe-area-top: 20px;
      --ion-safe-area-bottom: 22px;
    }
  </style>
  <script type="module">
    import { alertController } from 'https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/index.esm.js';
    window.alertController = alertController;
  </script>
</head>
<body>
  <ion-app>
    <ion-header translucent>
      <ion-toolbar>
        <ion-title>Alert</ion-title>
      </ion-toolbar>
    </ion-header>,
    <ion-content fullscreen class="ion-padding">
      <ion-alert-controller></ion-alert-controller>
      <ion-button expand="block">Show Alert</ion-button>
    </ion-content>
  </ion-app>

  <script>
    const button = document.querySelector('ion-button');
    button.addEventListener('click', handleButtonClick);

    async function handleButtonClick() {
      const alert = await alertController.create({
        header: 'Use this lightsaber?',
        message: 'Do you agree to use this lightsaber to do good across the galaxy?',
        buttons: ['Disagree', 'Agree']
      });

      await alert.present();
    }
  </script>
</body>
</html>

There is an element there with .alert-wrapper class on it.

if you'll look at the applied CSS, it will show you opacity: 0, but the computed shows opacity: 1 the element i'm inspecting

applied css

computed styles

I tried removing all the CSS Files from the page, all the javascript, all the other elements I tried to move this element to the body (outside the iframe) and applying the opacity: 0 in the styles, nothing helps, the computed stays opacity: 1..

How is this possible?

2

There are 2 answers

0
Kaiido On

They are using the Web Animations API.

elem.animate([{ opacity: "1" }],{duration: 1, iterations: 1, fill: "forwards"});
#elem {
  opacity: 0;
}
<div id="elem">Hello</div>

0
siddhant On

I think you already know this but have you tried using - !important

The initial value of opacity is - 1.0 Inherited - no Computed value -> the specified value, clipped in the range [0,1]

source - MDN