简体   繁体   中英

applied CSS rule for opacity is different from the computed styles

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 我正在检查的元素

应用CSS

计算样式

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?

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM