代码之家  ›  专栏  ›  技术社区  ›  jscheel

CSS中的灵活rgba颜色

  •  1
  • jscheel  · 技术社区  · 14 年前

    我正在尝试设计一个DataGrid组件的样式,以便背景是透明的(flex 4)。如果我在组件上使“alternatingitemcolors”属性为“alternatingitemcolors”,则rgba颜色可以正常工作,但是如果我尝试在CSS样式表中声明它,则无法声明alpha值。

    工程(MXML):

    <mx:DataGrid id="songGrid" width="800" height="529" dataProvider="{songs}" itemClick="handleRowClick(event);" x="145" y="168" headerStyleName="dataGridHeader" alternatingItemColors="[0xFFFFFFFF, 0xFFFFFFFF]">
    

    不工作(css) :

    mx|DataGrid {
        alternatingItemColors: #FFFFFFFF, #FFFFFFFF;
    }
    

    如果我输入值为“0xffffff”,我会得到一个解析错误,因为它不是正确的css(当然,大多数flex的css不是正确的css,但我会偏离…)。那么,有没有办法在CSS中声明这些颜色的alpha值呢?

    2 回复  |  直到 14 年前
        1
  •  1
  •   Robusto    14 年前

    您可以尝试扩展数据报并进行以下重写:

    override protected function drawRowBackground(s:Sprite, rowIndex:int,
                                y:Number, height:Number, color:uint, dataIndex:int):void {
        var background:Shape = Shape(s.getChildAt(rowIndex));
        background.alpha = 0.5; // or whatever alpha value you wish
        super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
    }
    
        2
  •  -1
  •   joeforker    14 年前

    CSS3透明度描述见 http://www.w3.org/TR/css3-color/#transparency . 从示例中,其中alpha是介于0(完全透明)和1(完全不透明)之间的数字:

    em { color: rgba(100%,0%,0%,1) } /* the same, with explicit opacity of 1 */

    推荐文章