繁体   English   中英

不透明度的应用 CSS 规则与计算样式不同

[英]applied CSS rule for opacity is different from the computed styles

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

那里有一个带有 .alert-wrapper 类的元素。

如果您查看应用的 CSS,它会显示 opacity: 0,但计算结果显示 opacity: 1 我正在检查的元素

应用CSS

计算样式

我尝试从页面中删除所有 CSS 文件、所有 javascript、所有其他元素,我尝试将此元素移动到正文(iframe 外)并应用 opacity: 0 在样式中,没有任何帮助,计算保持不透明度: 1..

这怎么可能?

他们正在使用Web Animations API

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

我想您已经知道这一点,但您是否尝试过使用 - !important

opacity 的初始值是 - 1.0 Inherited - no Computed value -> 指定值,裁剪在 [0,1] 范围内

来源 - MDN

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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