How to set opacity to the background color of a div? [duplicate]

﹥>﹥吖頭↗ 提交于 2019-11-30 00:21:17

问题


I have this class

.box { background-color:#fff; border:3px solid #eee; }

My question is how can I set an opacity to the white background only so that it will kinda mix with my background?

Thank you.


回答1:


CSS 3 introduces rgba colour, and you can combine it with graphics for a backwards compatible solution.




回答2:


I think rgba is the quickest and easiest!

background: rgba(225, 225, 225, .8)




回答3:


I think this covers just about all of the browsers. I have used it successfully in the past.

#div {
    filter: alpha(opacity=50); /* internet explorer */
    -khtml-opacity: 0.5;      /* khtml, old safari */
    -moz-opacity: 0.5;       /* mozilla, netscape */
    opacity: 0.5;           /* fx, safari, opera */
}



回答4:


You can use CSS3 RGBA in this way:

rgba(255, 0, 0, 0.7);

0.7 means 70% opacity.




回答5:


I would say that the easiest way is to use transparent background image.

http://jsfiddle.net/m48nH/

background: url("http://musescore.org/sites/musescore.org/files/blue-translucent.png") repeat top left;


来源:https://stackoverflow.com/questions/6624457/how-to-set-opacity-to-the-background-color-of-a-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!