Making text background transparent but not text itself

后端 未结 5 1561
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 23:53

So I am having a problem. I have looked around and looked around but no luck. I would like to make the background of my body transparent but leave the text non transparent.

相关标签:
5条回答
  • 2020-11-29 00:33

    For a fully transparent background use:

    background: transparent;
    

    Otherwise for a semi-transparent color fill use:

    background: rgba(255,255,255,0.5); // or hsla(0, 0%, 100%, 0.5)
    

    where the values are:

    background: rgba(red,green,blue,opacity); // or hsla(hue, saturation, lightness, opacity)
    

    You can also use rgba values for gradient backgrounds.

    To get transparency on an image background simply reduce the opacity of the image in an image editor of you choice beforehand.

    0 讨论(0)
  • 2020-11-29 00:43

    opacity will make both text and background transparent. Use a semi-transparent background-color instead, by using a rgba() value for example. Works on IE8+

    0 讨论(0)
  • 2020-11-29 00:49
    box-shadow: inset 1px 2000px rgba(208, 208, 208, 0.54);
    
    0 讨论(0)
  • 2020-11-29 00:50

    If you use RGBA for modern browsers you don't need let older IEs use only the non-transparent version of the given color with RGB.

    If you don't stick to CSS-only solutions, give CSS3PIE a try. With this syntax you can see exactly the same result in older IEs that you see in modern browsers:

    div {
        -pie-background: rgba(223,231,233,0.8);
        behavior: url(../PIE.htc);
    }
    
    0 讨论(0)
  • 2020-11-29 00:51

    Don't use opacity for this, set the background to an RGBA-value instead to only make the background semi-transparent. In your case it would be like this.

    .content {
        padding:20px;
        width:710px;
        position:relative;
        background: rgb(204, 204, 204); /* Fallback for older browsers without RGBA-support */
        background: rgba(204, 204, 204, 0.5);
    }
    

    See http://css-tricks.com/rgba-browser-support/ for more info and samples of rgba-values in css.

    0 讨论(0)
提交回复
热议问题