简体   繁体   English

使用IE10 +会显示这种方法

[英]With IE10+ would this method of showing <IE6 a jpg, and other browsers a png be an issue?

I'm looking to display a transparent png file, but would like to show IE6 a jpg to avoid an problems. 我希望显示一个透明的png文件,但想向IE6显示一个jpg以避免出现问题。 I know it's 2014 and IE6 should be forgotten about, but without too much effort my site still works with IE6, apart from this one little problem. 我知道应该忘了2014年和IE6,但是除了这个小问题之外,我的网站在没有太多努力的情况下仍然可以与IE6一起使用。

I had thought about simply using conditional comments to say: 我曾考虑过简单地使用条件注释说:

<!--[if lte IE6]>
 <img src="foo.jpg">
<![endif]-->
<![if !IE]>
 <img src="foo.png">
<![endif]>

However I'm not sure what the deal is with other browsers and the use of <![if !IE]> ? 但是,我不确定与其他浏览器有何关系以及<![if !IE]> Also with IE10 not supporting conditional comments, would this cause problems? 另外,如果IE10不支持条件注释,这会引起问题吗? Appreciate any clarification on this. 感谢对此的任何澄清。 Thanks. 谢谢。

UPDATE: After trying a few methods, I decided in the end to cheat a little. 更新:尝试了几种方法后,我最终决定作弊一点。 I got rid of conditional comments entirely and took a screenshot of what the image looked like in firefox with transparency and basically saved that as a jpg. 我完全摆脱了条件注释,并截取了萤幕在Firefox中具有透明性的图像的屏幕快照,并将其基本上保存为jpg。 Due to image involved and where it was in the layout, this worked perfectly. 由于涉及图像以及它在布局中的位置,因此效果很好。 Thanks to everyone's answers. 感谢大家的回答。

Try using <!--[if lte IE 6]> instead of <!--[if lte IE6]> 尝试使用<!--[if lte IE 6]>而不是<!--[if lte IE6]>

Example: 例:

<!--[if lte IE6]>
  <img src="foo.jpg">
<![endif]-->
<![if !IE]>
  <img src="foo.png">
<![endif]>

Forget the conditional comments and fix your PNG instead. 忘记条件注释并改正您的PNG。 The problem with PNGs when it comes to older IE versions is that when you use alpha transparency, you end up with an ugly grey background instead of nice transparency. 对于较旧的IE版本,PNG的问题在于,当您使用Alpha透明度时,最终会得到难看的灰色背景,而不是漂亮的透明度。 To avoid this, all you need to do is set the transparency correctly on an 8-bit PNG, something Photoshop's "save for web" dialog cannot do. 为避免这种情况,您所需要做的就是在8位PNG上正确设置透明度,这是Photoshop的“保存为网络”对话框无法做到的。

Fireworks 烟花

http://www.sitepoint.com/png8-the-clear-winner/ (I've personally used this and it works well, comes bundled in Adobe's Creative Suite) http://www.sitepoint.com/png8-the-clear-winner/ (我亲自使用过,效果很好,已捆绑在Adobe的Creative Suite中)

在此处输入图片说明

pngquant pngquant

http://cubicspot.blogspot.ca/2010/01/transparent-png8-is-solution-to-ie6.html http://cubicspot.blogspot.ca/2010/01/transparent-png8-is-solution-to-ie6.html

在此处输入图片说明

Even if you weren't trying to support IE6, I would recommend this for images that don't require more than 256 colors because it makes a significantly smaller image. 即使您不打算支持IE6,我也建议将它用于不需要超过256色的图像,因为它可以显着缩小图像。

Find a program that will let you modify the bKGD 查找一个程序,让您修改bKGD

The grey color that old IE versions display comes from a chunk of the PNG called "bKGD". 旧IE版本显示的灰色颜色来自称为“ bKGD”的PNG块。 If you can find a program that will let you modify this value to a more attractive color, you'll at least get something that looks the same as a JPEG for old browsers while having the alpha transparency in modern browsers. 如果您找到一个程序,可以将该值修改为更具吸引力的颜色,则至少会得到与旧浏览器的JPEG相同的外观,同时在现代浏览器中具有alpha透明度。

http://cubicspot.blogspot.ca/2010/03/pseudo-transparent-24-bit-png-in.html http://cubicspot.blogspot.ca/2010/03/pseudo-transparent-24-bit-png-in.html

See also: Software for creating PNG 8bit transparent images? 另请参阅: 用于创建PNG 8位透明图像的软件?

However I'm not sure what the deal is with other browsers and the use of <![if !IE]> ? 但是,我不确定与其他浏览器有何关系以及<![if !IE]> Also with IE10 not supporting conditional comments, would this cause problems? 另外,如果IE10不支持条件注释,这会引起问题吗?

If you convert the negated condition to proper HTML comment syntax, then it will not be a problem for other browsers or for IE10 and later: 如果将否定条件转换为正确的HTML注释语法,则对于其他浏览器或IE10及更高版本,这将不是问题:

<!--[if lte IE 6]>
 <img src="foo.jpg">
<![endif]-->
<!--[if !IE]><!-->
 <img src="foo.png">
<!--<![endif]-->

Notice the intermediate <!--> and <!-- delimiters, which split the negation and its endif into two separate comments allowing other browsers and newer IEs to see the PNG image. 注意中间的<!--><!--分隔符,它们将否定符和其结尾分隔成两个单独的注释,从而允许其他浏览器和较新的IE看到PNG图像。 Older IEs will continue to obey the condition and thus ignore that image. 较旧的IE将继续遵守条件,因此会忽略该图像。

Additionally, as mentioned in another answer, there should be a space after the IE token, so it should be IE 6 rather than IE6 . 另外,如另一个答案中所述, IE令牌后应该有一个空格,因此应该是IE 6而不是IE6

Other than these, I don't see anything else that's wrong with your conditional comments. 除此之外,我没有看到您的条件注释有其他问题。

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

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