HTML 正文 bgcolor 透明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23564182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:45:02  来源:igfitidea点击:

HTML body bgcolor transparent

htmlcssbackgroundbackground-color

提问by user2056563

I have this HTML

我有这个 HTML

<html>
<head>
</head>
<body bgcolor="#FFFFFF" 
style="margin:0px;padding:0px;" 
<div style=width:100%;color:#000000;padding:25px;font-family: Segoe UI;font-size: 17px;"></div></body></html>

Here i have set bgcolor="#FFFFFF"but i want it to be transparent how to do it ?

在这里我已经设置bgcolor="#FFFFFF"但我希望它是透明的怎么做?

回答by Quentin

HTML provides no means to specify a transparent background (and the means it has to specify backgrounds of any kind are obsolete and should not be used). You can do this in CSS.

HTML 没有提供指定透明背景的方法(它必须指定任何类型背景的方法已经过时,不应使用)。你可以在 CSS 中做到这一点。

body { 
    background-color: transparent;
}

This will make the background of the <html>element visible.

这将使<html>元素的背景可见。

There is no way to make the browser window transparent.

没有办法使浏览器窗口透明。

回答by display-name-is-missing

With inline-styling you can achieve this with:

使用内联样式,您可以通过以下方式实现:

<body style="background-color: transparent;">

But a better option is to put the following code:

但更好的选择是放置以下代码:

body { background-color:transparent; }

in a CSS file which you link to in the <head>section of the page like so:

在您链接到<head>页面部分的CSS 文件中,如下所示:

<link rel="stylesheet" type="text/css" href="NAMEOFFILE.css">

回答by Razvan B.

background-color: transparent;

Update
However, you HAVE NO WAY to make the browser window transparent. So, even if you use the code above, your background will still be white.

更新
但是,您无法使浏览器窗口透明。所以,即使你使用上面的代码,你的背景仍然是白色的。

回答by Guffa

You need to use CSS instead of HTML attributes to set transparent background:

您需要使用 CSS 而不是 HTML 属性来设置透明背景:

<body style="background: transparent; margin: 0; padding: 0;">

Preferably you should have a style sheet for the page where you put the styles instead of putting styles in the HTML elements.

最好你应该有一个用于放置样式的页面的样式表,而不是在 HTML 元素中放置样式。

Note: To have an iframe with a transparent background (which is the only way that a transparent background on a page can be used) you need to add the allowtransparencyattribute to the iframe tag for it to work in IE:

注意:要使 iframe 具有透明背景(这是可以在页面上使用透明背景的唯一方法),您需要将allowtransparency属性添加到 iframe 标记,以便它在 IE 中工作:

<iframe .... allowtransparency="true"></iframe>

回答by Samat Baltin

body {

    background-color: rgba(255, 255, 255, 0.5)
};

last value is alpha - it will set transparency values between 0 and 1; 0 transparent;

最后一个值是 alpha - 它将设置介于 0 和 1 之间的透明度值;0 透明;