℡Wang Yan 2011-02-27 18:30 采纳率: 100%
浏览 511
已采纳

Css 只透明到背景颜色而不透明到上面的文字? [重复]

This question already has an answer here:

Can I assign the opacity property to the background property of a div only and not to the text on it?

I've tried:

background: #CCC;
opacity: 0.6;

but this doesn't change the opacity.

</div>

转载于:https://stackoverflow.com/questions/5135019/css-opacity-only-to-background-color-not-the-text-on-it

  • 写回答

11条回答 默认 最新

  • YaoRaoLov 2011-02-27 18:32
    关注

    It sounds like you want to use a transparent background, in which case you could try using the rgba() function:

    rgba(R, G, B, A)

    R (red), G (green), and B (blue) can be either <integer>s or <percentage>s, where the number 255 corresponds to 100%. A (alpha) can be a <number> between 0 and 1, or a <percentage>, where the number 1 corresponds to 100% (full opacity).

    RGBa example

    rgba(51, 170, 51, .1)    /*  10% opaque green */ 
    rgba(51, 170, 51, .4)    /*  40% opaque green */ 
    rgba(51, 170, 51, .7)    /*  70% opaque green */ 
    rgba(51, 170, 51,  1)    /* full opaque green */ 
    

    A small example showing how rgba can be used.

    As of 2018, practically every browser supports the rgba syntax.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用