Lotus@ 2011-02-27 18:30 采纳率: 100%
浏览 439
已采纳

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条回答 默认 最新

  • 零零乙 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条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决