Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

html - transparency and text problem

I'm playing with the opacity CSS attribute.

It works nicely for the box (with at 50% or black at 30%) - the problem is that the text inside the box is also transparent.

I would like the text to be 100% white in a box with at 30% transparency.

The solution is to use CSS with tweaks or to use a .png for the background and to forget the opacity setting.

Tell me, how to do 30% opacity with 100% opacity text inside.

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your choices are:

  • Using CSS3: background: rgba(255, 255, 255, 0.3). Live Demo
  • Absolutely position two <div> tags on top of each other. One of them is the background, and has the opacity setting. The second one has the text in it, and a transparent background.
  • As you hinted at in your question, you could use a .png file with 30% transparency.

I knew I'd read about a way to make the rgba work in IE.

See: http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/

.alpha60 {
    /* Fallback for web browsers that doesn't support RGBa */
    background: rgb(0, 0, 0);
    /* RGBa with 0.6 opacity */
    background: rgba(0, 0, 0, 0.6);
    /* For IE 5.5 - 7*/
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);
    /* For IE 8*/
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)";
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...