javascript - 通过 CSS(网格支持)显示浏览器兼容性警报
问题描述
我可以检测浏览器支持并显示关于 CSS 网格与 JS 的兼容性的“警报”(样式化的 div):
function isUpToDate() {
var div = document.createElement('div')
div.style.display = 'grid'
return div.style.display === 'grid'
}
if (!isUpToDate) {
displaySomethingAboutBrowserCompatibility()
}
原始 CSS 中有没有办法做这种事情:使用 CSS 规则绘制一个 div,使 div 仅在不支持网格时才可见?
解决方案
您可以为此使用@supports。
默认显示警告,如果支持您想要的功能则隐藏。
div {
display: block;
margin: 1em;
text-align: center;
border: solid red 4px;
}
@supports(display: grid) {
.grids { display: none; }
}
@supports(display: fakedisplay) {
.fakedisplay { display: none; }
}
<div class="grids">Grid is not supported</div>
<div class="fakedisplay">Fake Display is not supported</div>
推荐阅读
- sql-server - 尝试创建存储过程时出错
- php - 函数调用中需要身份验证的 PHP SOAP 客户端
- linux - func (N) 在手册页中是什么意思?
- python - 从运行 Python 脚本的批处理文件中读取输出
- angular - 带有引导程序 4 的 Angular 6 - 表单验证电子邮件
- r - 如何在 lapply 中分配一个字符以评估循环 r 中的函数
- javascript - 我如何获得同名Javascript中的最后一个值
- ios - UI 元素未显示它们在 xcode 中故事板上的实际位置
- r - 如何在R中使用具有下限和上限的总和
- docker - Docker 上的 RabbitMQ。不创建 cookie / 找不到主机?