惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - sin

2017年6月做的一个梦 开始写诗了 一张判断你是用左脑还是右脑的图 Javascript 刷新框架及页面的方法总集 - sin SQL高级查询技巧 - sin 自己写的SQL存储过程分页方法 .net简单添加数据库方法 ASP.NET刷新页面的六种方法 - sin DataGrid传统分页方式 - sin ACCESS"数据库提示它已经被别的用户以独占方式打开,或没有查看数据的权限"的问题 - sin div长度相等的几个办法 在IE浏览器中的奇怪页面表现 - sin HTML标签大全 css杂问题 - sin 用css模拟title和alt的提示效果 用Web标准进行开发 div+css 面试题目 有什么有效方法清除多余的CSS代码 95%的中国网站需要重写CSS-写在px和em的区别下 - sin
png图片在ie不透明的解决方案和浏览器通用的透明效果
sin · 2007-06-22 · via 博客园 - sin

PNG(Portable Network Graphics)是W3C推荐的网页图片通用格式,但是Microsoft的IE6以下(IE7已经支持)没有把PNG的Alpha 通道打开,造成透明PNG图片的效果出不来。在Firefox、Opera下显示正常的透明PNG图片,在IE下浏览时就会带有灰色背景色,不透明的就像下图示例:

解决方法之一是给透明PNG图片加一个滤镜:

引用内容 引用内容

<div style="width:100%;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='透明PNG图片路径',sizingMethod='image')></div>

或是用CSS的方式控制,把style写在CSS文件中,就不用每贴一张图都要写这么长的代码了。

透明的效果就像这样:

HTML代码



[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

第二种方法就是用javascript来控制,程序代码如下:

引用内容 引用内容

<script>
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span "+ imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src='" + img.src + "', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);

</script>

在页面中加入此代码PNG图片即可透明。。。

浏览器通用透明效果:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>runcode</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="Sheneyan" />
<style type="text/css">
body{background:gray;}
div#test{
  background:#000;
  color:white;
  width:200px;
  position:absolute;
  left:10px;
  top:10px;
  filter: Alpha(opacity=50);
  -moz-opacity:.50;
  opacity:0.5;
}
</style>

</head>
<body>
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
这里是一堆文字背景~<br />
<div id="test">我应该是半透明的……</div>
</body>
</html>