Html html透明背景

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2752406/
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 02:56:14  来源:igfitidea点击:

html transparent background

htmlcssbackgroundtransparent

提问by user315067

I want to create a webpage with transparent background, a table and some text. I have seen posts related to this, but due to my lack of familiarity with css, I somehow cant get my code to work. I just want a transparent background, while this code is making everything transparent. Can someone kindly help.

我想创建一个具有透明背景、表格和一些文本的网页。我看过与此相关的帖子,但由于我对 css 不熟悉,我以某种方式无法让我的代码工作。我只想要一个透明的背景,而这段代码使一切变得透明。有人可以帮忙吗。

<html>
<head><style type="text/css">
  div.transbg {background-color:#4a6c9b; opacity:0.6;}
</style></head>
<div class="transbg">
<body><Center><font color="#FFFFFF">
  <b>Toll Charges</b>
  <table bgcolor="#000000" cellspacing=3>
    <tr>
      <td bgcolor="#009900"><font color="#FFFFFF" align="left"> &nbsp; &nbsp;Class 2 inc Private&nbsp;</font></td>
      <td bgcolor="#009900"><font color="#FFFFFF" align="right"> &nbsp;A$ 4.95 &nbsp;</font></td>
    </tr>
    <tr>
      <td bgcolor="#009900"><font color="#FFFFFF" align="left"> &nbsp; &nbsp;Class 2 inc Commercial&nbsp;</font></td>
      <td bgcolor="#009900"><font color="#FFFFFF" align="right"> &nbsp;A$ 13.95 &nbsp;</font></td>
      </tr>
    </table>
    <br>
    Toll has to be paid within 48 hrs of passage, else an additional A$ 13.95 of administration charges would be added
    </font></Center>
</div>
</body>
</html>

Update

更新

Great thanks for all the answers people. I have solved the problem in another way for the moment. Actually, I writing an iPhone app which uses Webview to display some html. I wanted to give webview a transparent look, which can be achieved by setting the alpha for the webview itself in interface builder. It kinda saying, make my entire web browser 50% transparent. I would like to thank everyone for their help here.

非常感谢人们的所有回答。我暂时用另一种方式解决了这个问题。实际上,我正在编写一个 iPhone 应用程序,它使用 Webview 来显示一些 html。我想给 webview 一个透明的外观,这可以通过在界面构建器中设置 webview 本身的 alpha 来实现。有点说,让我的整个网络浏览器 50% 透明。我要感谢大家在这里的帮助。

回答by user295292

I believe you're looking for this,

我相信你正在寻找这个,

.transbg {
    background-color:#4a6c9b;
filter:alpha(opacity=60);
-moz-opacity:0.6;
-khtml-opacity: 0.6;
opacity: 0.6;
}

and maybe this http://css-tricks.com/rgba-browser-support/

也许这个http://css-tricks.com/rgba-browser-support/

回答by Jonno_FTW

I suggest using rgba instead of opacity, thusly:

我建议使用 rgba 而不是不透明度,因此:

.transbg {background: rgba(red,green,blue,opacity);}

You can also put the rest of your formatting into CSS like this:

您还可以将其余的格式放入 CSS 中,如下所示:

body {background-color:#000;
      color:#fff;}
td {background-color: #090;
    color:#fff;}
.leftc {text-align:left;}
.rightc {text-align:right;}
table {borderspacing: 3;}

Now you can remove the font tags and the attributes of td. All you'd need for td is <td class="leftc">or with the rightcclass for text to the right.

现在您可以删除字体标签和 td 的属性。td 所需要的只是<td class="leftc">或使用rightc右侧的文本类。

See also http://css-tricks.com/rgba-browser-support/

另见http://css-tricks.com/rgba-browser-support/

回答by john.k.doe

I recently discovered that I wanted to create an HTML body with a transparent background. (The HTML is a localized information page of instructions for an app, and will appear a "browser" that is really just a Webkit view within another set of views. The Webkit view sits on top of an image in the view hierarchy. By making the web page background transparent, the image from the view behind the Webkit view shows up.)

我最近发现我想创建一个具有透明背景的 HTML 正文。(HTML 是应用程序指令的本地化信息页面,将出现一个“浏览器”,它实际上只是另一组视图中的 Webkit 视图。Webkit 视图位于视图层次结构中的图像顶部。通过网页背景透明,Webkit 视图后面的视图显示出来。)

To accomplish this, just code the HTML as follows, together with any other attributes/styles/etc:

要实现这一点,只需按如下方式编写 HTML 以及任何其他属性/样式/等:

<body bgcolor=transparent>

In other words, use the keyword "transparent" withoutthe quotes, and you will get an alpha of 0 and thus a transparent background to allow whatever is behind to show through.

换句话说,使用不带引号的关键字“transparent” ,您将获得 0 的 alpha 值,因此透明背景可以让后面的任何内容显示出来。

(Caveat: In the Webkit view implementation I have, I also have to make the Webkit background color transparent in my UI setup. I.E. both must be in place for this to work as I have it.)

(警告:在我拥有的 Webkit 视图实现中,我还必须在我的 UI 设置中使 Webkit 背景颜色透明。IE 两者都必须到位才能像我拥有的​​那样工作。)

回答by BalusC

I'm not sure if your requirement makes sense. Just give the background the desired color.

我不确定您的要求是否合理。只需为背景提供所需的颜色。

div.transbg { background-color: #92a7c3; }

Transparency is only interesting for background images or overlayed backgrounds, which doesn't seem to be applicable in your particular case.

透明度仅对背景图像或叠加背景有用,这似乎不适用于您的特定情况。