在Android浏览器中使用CSS的反射渐变
我有一些 CSS 用于在使用 -webkit-gradient 淡出的元素上显示反射:
.foo { -webkit-box-reflect: below 0 -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), to(rgba(255, 255, 255, 0.5)), color-stop(0.7, transparent)); }
- 在支持 -webkit-box-reflect 的浏览器(例如 chrome)上,这会显示元素的反射,该元素会按预期逐渐淡出。
- 在根本不支持它的浏览器上,不会显示任何反射。
但是,在 Android 浏览器上,会显示反射,但不会淡出。
有没有办法让 Android 要么
- 淡出反射,要么
- 根本不显示反射。
我知道我可以使用 javascript 来检测浏览器并相应地更改样式,但我更喜欢仅 CSS 的解决方案。
I have some CSS for displaying a reflection on an element which uses -webkit-gradient to fade out:
.foo { -webkit-box-reflect: below 0 -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), to(rgba(255, 255, 255, 0.5)), color-stop(0.7, transparent)); }
- On browsers which support -webkit-box-reflect such as chrome, this displays a reflection of the element which gradually fades out as expected.
- On browsers which don't support it at all, no reflection is show.
However, on Android's browser, a reflection is shown, but doesn't fade out.
Is there any way of getting Android to either:
- fade out the reflection, or
- not show the reflection at all.
I know I could use javascript to detect the browser and change the style accordingly, but I'd much prefer a CSS-only solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果没有示例文件或链接,就很难看到您需要什么。
几个月前我也玩过一些反思的东西,但没有找到任何可以做你所描述的事情。我有一些步骤可以让您在代码之外得到您想要的东西。首先,我建议您希望反映的项目是透明背景上的 PNG。
步骤:
1.将图像导入您最喜欢的图像处理程序(例如 Photoshop) 将
Without an example file or link, it is a little difficult to see what you need.
I also played with some reflection stuff a few months ago and didn't find anything that could do what you describe. I have some steps to get you what you want, outside of code. I recommend the item you wish to reflect be a PNG on a transparent background, to start.
The steps:
1.Take the image into your favorite image manipulation program (ex. Photoshop)
CSS 的设计初衷并不是为了处理类似的事情。换句话说:不,这是不可能的。
CSS isn't designed to handle stuff like that. In other words: no, it's not possible.
我在尝试在 Android 浏览器中使用背景渐变做事情时遇到了类似的问题,并且它似乎完全不受支持
不幸的是上面的答案是正确的,没有办法以一种很好的逐步增强的方式分割您的声明。您可以像您提到的那样使用 JavaScript/modernizr,并且至少设置一个支持类,这样您实际上不必在代码中翻转样式。
您可以尝试使用 HTML canvas 元素重现此效果,对图像使用 drawImage 并对其进行转换。尽管 canvas 在移动 webkit 中可能会很慢。
祝你好运
I'm having similar problems trying to do things with background gradients in the Android browser, and it appears completely unsupported
Unfortunately the above answer is right, there isn't a way to split your declaration up in a nice progressively enhanced way. You could use JavaScript/modernizr as you mentioned, and at least set a support class(es) so you don't actually have to flip the style within code.
You could try reproducing this effect with a HTML canvas element, using drawImage with your image and transforming it. Although canvas can be slow in mobile webkit.
Good luck
渐变在 Android 浏览器中起作用吗?
如果这样做,请确保您使用的是正确的版本。您可能需要使用旧的 webkit 格式。
如果没有,就用modernizr把它隐藏在不支持渐变的地方。
do gradients work at all in the android browser?
if they do, make sure you're using the correct version. There's an old webkit format you may need to use.
If not, just use modernizr to hide it on places that don't support gradients.