百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

compass-rgbapng

> 编程语言
开源

Compass 插件用于为不支持 RGBA 的浏览器提供跨浏览器兼容的 RGBA 支持,通过即时创建透明 PNG 文件。它使用纯 R

156 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Compass 插件用于为不支持 RGBA 的浏览器提供跨浏览器兼容的 RGBA 支持,通过即时创建透明 PNG 文件。它使用纯 R

rgbapng - Compass plugin

rgbapng is a Compass plugin for providing cross-browser* compatible RGBA support. It works by creating single pixel alpha-transparent PNGs on the fly for browsers that don't support RGBA. It uses the pure Ruby ChunkyPNG library resulting in hassle-free installation and deployment.

Installation

Installation is simple via Ruby Gems. Compass and ChunkyPNG are required.

gem install compass-rgbapng

Using rgbapng with your Compass project

To use rgbapng with your project, require the plugin from your Compass configuration:

require "rgbapng"

And then import the mixins to your SASS/SCSS files:

@import "rgbapng";

Configurable variables

There are two customzable global variables. This first $rgbapng_path defines the path to which your PNG images will be saved. This defaults to rgbapng inside your Compass images directory. The second $rgbapng_px_size defines the pixel square size of the generated png. This defaults to a 5x5 square.

$rgbapng_path: 'my_pngs';
$rgbapng_px_size: 8;

Mixins

There are two mixins available to you.

rgba-background($color, [$path, $pixel])

Sets the background property to use the RGBA value, falling back to the compiled PNG.

@include rgba-background(rgba(0,0,0,0.75));

Compiles to:

background: url('/images/rgbapng/000000bf.png?1282127952');
background: rgba(0, 0, 0, 0.75);

rgba-background-inline($color, [$pixel])

Sets the background property to use the RGBA value, falling back to a base64 encoded image data.

@include rgba-background-inline(rgba(0,0,0,0.75));

Compiles to:

background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNh2A8AAM4AxOSyusMAAAAASUVORK5CYII=');
background: rgba(0, 0, 0, 0.75);

Functions

There are two Sass::Script functions which can be used in your SASS:

# Creates the single pixel PNG image
# Returns a String of the image path and filename
png_pixelate(color, [dir])

# Returns a String of the base64 encoded image data
png_base64(color)

* Cross-browser? Really?

OK, caveat time. When I say "cross-browser", what I really mean is all browsers that either natively support RGBA or support alpha-transparent PNGs. What I don't mean, is IE6. If alpha-transparency in IE6 is important to you, here are some suggestions:

  • Use DD_BelatedPNG JavaScript library to bootstrap PNG support to IE6.
  • Don't use this plugin at all and instead create your own mixin using Microsoft's proprietary filters - just make sure you wash your hands afterwards!
  • Be a rebel and either forget about IE6 or serve it up a universal stylesheet.

The choice is yours.

Credit where it's due

  • The CSS technique used was initially described by Lea Verou in Bulletproof, cross-browser RGBA backgrounds, today.
  • The SASS functions were first created by Benjamin Doherty using the RMagick library.

Copyright

Copyright (c) 2010 Aaron Russell. See LICENSE for details.

Issues· 4 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言