简体   繁体   English

如何在CSS中制作不透明背景?

[英]How can i make the opacity background in css?

I created the popup for the facebook when the popup load the entire background is goes to something like color code #ccc; 当弹出窗口加载整个背景时,我为Facebook创建了弹出窗口,例如颜色代码#ccc;。 which can i view the inside content also. 我也可以查看内部内容。 How can do this in css here is the code that i tried . 如何在CSS中执行此操作,这是我尝试过的代码。

#ptechsolfb {display:none;
background-color:#ccc transparent;
width:100%;
height:100%;
position:fixed;
top:0;
left:0;
z-index:999999999;
opacity: 1; } 

How can i do this. 我怎样才能做到这一点。 Any One would be much appreciated. 任何人将不胜感激。

Background opacity is achieved using rgba . 使用rgba可实现背景不透明。 For instance, this would create a black background ( #000 or rgb(0,0,0) ) with 50% ( 0.5 ) opacity: 例如,这将创建具有50%( 0.5 )不透明度的黑色背景( #000rgb(0,0,0) ):

element {
    background-color:rgba(0, 0, 0, 0.5);
}

JSFiddle example . JSFiddle示例

To give a background of #CCC ( rgb(204, 204, 204) ) 75% opacity, you'd use: 要使背景#CCCrgb(204, 204, 204) #CCC rgb(204, 204, 204) )的不透明度为75%,您可以使用:

element {
    background-color:rgba(204, 204, 204, 0.75)
}

The correct way to make only the background opaque would be to apply an rgba color: 仅使背景不透明的正确方法是应用rgba颜色:

background:rgba(204,204,204,0.5);

This is the equivalent of #ccc but semi-transparent because it has an alpha value of 0.5 . 这与#ccc等效,但是半透明的,因为它的alpha值为0.5

If you change the opacity value for the entire div its contents will also go semi-transparent, which is not the intended behaviour. 如果您更改整个divopacity值,则其内容也将变为半透明,这不是预期的行为。

try something like this: 尝试这样的事情:

.Background
{
background-color:white;
background: rgba(0, 0, 0, 0.5);
}

For background transparency, you need an rgba color definition. 为了使背景透明,需要一个rgba颜色定义。 This would look like this: 看起来像这样:

background-color:rgba(200, 200, 200, 0.5);

Where the first three numbers are the red, green and blue components, and the fourth number is an opacity percentage for the 'alpha channel'. 前三个数字是红色,绿色和蓝色分量,第四个数字是“ alpha通道”的不透明度百分比。

However, please note that this syntax isn't supported in IE8 or earlier. 但是,请注意,IE8或更早版本不支持此语法。 It does work in pretty much all other current browsers, but IE8 support may be a problem for you. 它几乎可以在所有其他当前浏览器中运行,但是IE8支持可能对您来说是个问题。

If you need to support IE8, my suggestion is to use CSS3Pie , which is a polyfill script that adds support for this feature (and a load of other stuff) to old IE versions. 如果您需要支持IE8,我的建议是使用CSS3Pie ,这是一个polyfill脚本,可以在旧IE版本中添加对此功能的支持(以及其他功能)。

Hope that helps. 希望能有所帮助。

about the value for opacity: 关于不透明度的值:

"Specifies the opacity. From 0.0 (fully transparent) to 1.0 (fully opaque)" “指定不透明度。从0.0(完全透明)到1.0(完全不透明)”

Here is the link: http://www.w3schools.com/cssref/css3_pr_opacity.asp 这是链接: http : //www.w3schools.com/cssref/css3_pr_opacity.asp

AND it wont work like you wrote it: 而且它不会像您写的那样工作:

background-color:#ccc transparent;

You have to remove the transparent atribute from background-color property: 您必须从background-color属性中删除透明属性:

background-color:#ccc;

If you want a (nearly) cross-browser solution, you can try: 如果您想要(几乎)跨浏览器的解决方案,可以尝试:

.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)";
}

Where for IE, the first Hex pair (99) controls the opacity. 对于IE,第一对十六进制(99)控制不透明度。

Source here . 来源在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM