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

响应本机CSS以使父容器透明

  •  1
  • xiaolingxiao  · 技术社区  · 7 年前

    我正在制作一个应用程序,它的页脚非常类似于Snapchat,其中有三个图标对下面的内容是不透明的,但容器是透明的。其效果应该类似于Web CSS中的要求: How to make parent transparent but not the child? . 我当前的页脚如下:

            <View style={appFooter.container}>
                <Grid>
    
                    <Col size={17} > </Col>
    
                    <Col size={22} style={feedItem.centerItems}>
                        <Profile active={onProfile}/>
                    </Col>
    
                    <Col size={22} style={feedItem.centerItems} >
                        <Spice active={onFire} />
                    </Col>
    
                    <Col size={22} style={feedItem.centerItems}>
                        <News active={onNews} />
                    </Col>
    
                    <Col size={17} > </Col>
    
                </Grid>
            </View>
    

    CSS的位置:

    container : {
    
          position: 'absolute'
        , bottom  : 0
        , left    : 0
        , right   : 0
        , height  : 50
    
        // , backgroundColor: 'rgba(0,0,0,0.1)'
         // '#00000000'
        , opacity : 0.8
    
    
        , flexDirection  : 'column'
        , justifyContent : 'center'
        , alignItems     : 'center'
    
    },
    

    正如你在评论中看到的,我已经尝试过解决方案 rgba(...) 但它没有给我想要的效果。现在 opacity: 0.8 解决方案给了我一个页脚容器 它的孩子 0.8 不透明度。但理想情况下,只有页脚是透明的。三个子图标是不透明的。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Martijn    7 年前

    你不能试着去做。当您将组件设置为80%不透明度时,它和它的子组件的最大不透明度为80%。孩子们永远不能超过80%。

    解决方法在于你的评论尝试。通常人们需要背景transparant,这就是rgba()发挥作用的地方。用它来设置透明度。

    使事情变得越轨的可能解决方案是:

    • 使用 opacity 也会使所有的孩子都褪色
    • 使用rgba()并将alpha设置为所需的不透明度
    • 使用半超偏执图像作为背景
    • 在要受影响的元素中定位一个绝对的DIV(应该是相对的和超偏执的)。
        2
  •  0
  •   Jeffraux    7 年前

    试试这个:

    backgroundColor: 'transparent'

    有一个“透明”枚举用于 backgroundColor .