CSS 过滤器不适用于 Chrome 和 Firefox 中的正文

标签 css google-chrome google-chrome-extension

我想创建一个 chrome 扩展,为色盲测试做一些过滤,并想使用 css/svg 过滤器,但过滤器不影响 body 背景有问题。

有什么建议吗?

链接到 codepen(在 Chrome 中测试)或查看下面的屏幕截图: http://codepen.io/larsenwork/pen/oZvdzX/?editors=1100

html {
	filter: grayscale(100%);
}

body, div {
	background-color: cyan;
}



/* Codepen style (ignore) */
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body { 
	min-height: 100vh;
	padding: calc(3vh + 3vw);
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	font-family: sans-serif;
	font-weight: 700;
	font-size: calc(3vh + 3vw);
	line-height: 1.3;
}

div {
	margin: 0 calc(-.5vh - .5vw);
	padding: 0 calc(.5vh + .5vw);
}

small { 
	font-size: .6em;
	margin-top: 2em;
}

pre {
	font-weight: normal;
}
In Chrome: Why is the body bg not gray
<div>When this is?</div>





<small>Same result (i.e. not applied to body) with e.g. <pre>filter: hue-rotate(90deg);</pre>or<pre>filter: url("#grayscale");</pre></small>

<!-- Used for alt filter test -->
<svg version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='saturate' values='0'/></filter></svg>

Chrome + 火狐浏览器: Chrome Screenshot

Safari : Safari Screenshot

最佳答案

所以我找到了一个解决方案(对此并不满意)但是设置了一个背景属性,例如 background-color: magenta;background-image: url(""); 在 html 上修复了 chrome 和 Firefox 中的问题

链接到工作版本: http://codepen.io/larsenwork/pen/mWbjJY?editors=1100

html {
    filter: grayscale(100%);
    background-color: magenta;
}

body, div {
    background-color: cyan;
}

关于CSS 过滤器不适用于 Chrome 和 Firefox 中的正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42400970/

相关文章:

javascript - 单击菜单时触发事件

javascript - chrome.serial/chrome.usb 未定义

javascript - 悬停在 "slider"中更改图像

javascript - 使用 jQuery 平滑地过渡滚动图像

html - Bootstrap 上的自定义列大小(不影响响应式设计)

angularjs - ngGrid 2.0.14 行选择不适用于新版 Google Chrome 和 ngAnimate

html - 3个div没有对齐

Android Chrome 表格边框问题

javascript - Chrome 和 Firefox 的 window.close() 方法的替代方法

javascript - 如何撤销 Identity API token (Chrome 扩展)