在Android浏览器中使用CSS的反射渐变

发布于 2024-11-14 01:51:40 字数 543 浏览 4 评论 0原文

我有一些 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 要么

  1. 淡出反射,要么
  2. 根本不显示反射。

我知道我可以使用 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:

  1. fade out the reflection, or
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

日暮斜阳 2024-11-21 01:51:40

如果没有示例文件或链接,就很难看到您需要什么。

几个月前我也玩过一些反思的东西,但没有找到任何可以做你所描述的事情。我有一些步骤可以让您在代码之外得到您想要的东西。首先,我建议您希望反映的项目是透明背景上的 PNG。

步骤:
1.将图像导入您最喜欢的图像处理程序(例如 Photoshop) 将

  1. 图像画布加倍或扩展必要的量,以包括适当方向的反射
  2. 复制图层(Photoshop 图层/复制图层)
  3. 反射图像。 (Photoshop 图层/图像旋转/翻转画布(您的方向)
  4. 使用“移动”工具移动复制的图层,使其显示为镜子。
  5. 选择 Marquis 工具,并将边缘模糊设置为大约 50原始图像宽度的%。
  6. 将光标拖动到“反射”图层上,如果它说选择线不可见,请不要担心,除非它说没有选择任何内容。如果提示未选择任何内容,请将边缘模糊减少到 25% 左右,然后重试。
  7. 一旦做出选择,无论其可见与否,都可以删除所选区域。这应该会给你一个“反射”的外观。
  8. 如果需要,可以在其他图层下方的图层上添加背景。
  9. 如果没有透明背景,请将图像另存为 jpg 格式;如果有透明背景,则将图像另存为 png 格式。使用它来代替您用代码反射和淡化的图像。这将主要与浏览器兼容。

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)

  1. Double or extend the image canvas the necessary amount to include the reflection in the appropriate direction
  2. Duplicate the layer (Photoshop-Layer/Duplicate Layer)
  3. Reflect the image. (Photoshop-Layer/Image Rotation/Flip Canvas (your direction))
  4. Move the duplicated layer such that it appears as a mirror using the Move tool
  5. Select the Marquis tool, and set the edge blur to about 50% of your original image width.
  6. Drag your cursor over the "reflected" layer, don't worry if it says the selection lines won't be visible, unless it says nothing was selected. If it says nothing was selected, reduce your edge blur to about 25% and try again.
  7. Once you have a selection, be it visible or not, delete the selected area. This should give you a "reflected" look.
  8. If desired, add a background on a layer below everything else.
  9. Save your image as a jpg if you don't have a transparent background or a png if you do. Use it in place of the image you were reflecting and fading with code. This will be mostly browser compatible.
日暮斜阳 2024-11-21 01:51:40

CSS 的设计初衷并不是为了处理类似的事情。换句话说:不,这是不可能的。

CSS isn't designed to handle stuff like that. In other words: no, it's not possible.

佼人 2024-11-21 01:51:40

我在尝试在 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

夏日落 2024-11-21 01:51:40

渐变在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文