Angular 14 不尊重浏览器兼容性:CSS:尽管不受支持,但使用了 inset 属性。

huangapple go评论70阅读模式
英文:

Angular 14 does not respect browser compatibility: CSS:inset property used although not supported

问题

我有一个基于Cordova/Ionic、Angular 14构建的应用程序。在Chrome和iOS上一切正常运行。然而,Android的WebView似乎不支持CSS的inset属性,这导致了问题,因为Angular将top: 0; ...编译为inset: ...。我无法更改这个行为。

在xy.component.scss文件中的以下CSS代码:

::ng-deep sc-modal-wizard-page > div:not(.defines-height) {
    position: absolute;
    top: 0px !important;
    bottom: 0px !important;
    left: 0px !important;
    right: 0px !important;
    overflow: auto;
}

通过Angular编译后变成了以下样子:

sc-modal-wizard-page>div:not(.defines-height){
    position:absolute;
    inset:0;
    overflow:auto
}

当在Android上运行打包后的应用程序(模拟器或物理设备无差异)时,定位不起作用。WebView调试显示,inset:0不被接受('无效的CSS值')。

手动通过DevTools添加left, top, bottom, right值可以解决此问题。

Android System WebView版本为83.0.4103.106。关于版本,我不太确定,但假设83对应于Chromium版本号。由于支持inset的功能是在Chrome 87中添加的,这可能解释了这种行为。

我现在正在尝试让Angular相应地编译,但没有成功。我添加了一个.browserslistsrc文件和相应的包(npm i browserslist)。为了测试目的,我配置了与所有Chrome版本兼容的文件:

# 此文件目前由autoprefixer使用,以调整CSS以支持下面指定的浏览器
# 有关格式和规则选项的其他信息,请参见:
# https://github.com/browserslist/browserslist#queries
# 对于IE 9-11支持,请取消注释文件的最后一行并根据需要进行调整
Chrome >= 0
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
# IE 9-11

然而,输出仍然包含inset属性。如何让Angular编译应用程序,以考虑指定的浏览器能力?

英文:

I have an app built based on Cordova/Ionic, Angular 14. Everything is working fine in Chrome and on iOS. However, the Android webview doesn't seem to support the CSS's inset-property, which leads to issues, as Angular compiles top: 0; ... to inset: .... I am failing to change this behavior.

The following css in a xy.component.scss file:

::ng-deep sc-modal-wizard-page > div:not(.defines-height) {
    position: absolute;
    top: 0px !important;
    bottom: 0px !important;
    left: 0px !important;
    right: 0px !important;
    overflow: auto;
}

get's compiled to the following by Angular:

sc-modal-wizard-page>div:not(.defines-height){position:absolute;inset:0;overflow:auto}

When running the bundled app on Android (emulator or physical device does not make a difference), the positioning does not work. WebView debugging shows, that inset:0 is not accepted ('invalid css value').

Angular 14 不尊重浏览器兼容性:CSS:尽管不受支持,但使用了 inset 属性。

Manually adding the left, top, bottom, right values via DevTools fixes the issue.

Android System WebView is version 83.0.4103.106. I am unsure regarding the versioning, but suppose that 83 corresponds to the chromium version number. As support for inset was added in Chrome 87, this would explain the behavior.

I am now trying to get Angular to compile accordingly, but without success. I added a .browserslistsrc file and the according package (npm i browserslist). For testing purposes I configured the file for compatibility with all versions of Chrome:

# This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# For IE 9-11 support, please uncomment the last line of the file and adjust as needed
Chrome >= 0
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
# IE 9-11

However, the output still contains the inset property. How can I get Angular to compile the application, respecting the specified browser capabilities?

答案1

得分: 2

我曾经遇到类似的问题

在我的情况下,较旧的Safari是个问题,将以下内容添加到.browserslistrc文件有帮助:

ios 14
英文:

I've had a similar issue.

In my case older Safari was an issue, adding this to .browserslistrc helped:

ios 14

答案2

得分: 0

另一种特定情况下的解决方法是将CSS规则中的top, right, bottom, left修改为!important。无法使用inset来有效表示这一点,因此在编译时保持明确的属性:

::ng-deep sc-modal-wizard-page > div:not(.defines-height) {
    position: absolute;
    top: 0px !important;
    bottom: 0px;
    left: 0px;
    right: 0px;
    overflow: auto;
}
英文:

Another workaround for the specific case is to modify the CSS rule mark only of top, right, bottom, left as !important. There is no viable representation of this using inset, thus the explicit properties are maintained at compilation:

::ng-deep sc-modal-wizard-page > div:not(.defines-height) {
    position: absolute;
    top: 0px !important;
    bottom: 0px;
    left: 0px;
    right: 0px;
    overflow: auto;
}

huangapple
  • 本文由 发表于 2023年1月9日 19:30:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056648.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定