在HTML中使用条件注释 [英] Using conditional comments in HTML

查看:152
本文介绍了在HTML中使用条件注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对网络开发和学习总是比较陌生。我最近在查看不同网站的源代码时遇到条件注释。我想我现在明白他们做什么,但不确定何时使用它们。

I am relatively new to web development and learning all the time. I have recently come across 'Conditional Comments' when viewing source code for different websites. I think i now understand what they do but am unsure as to when to use them.

我看到他们主要用于实现不同的样式表,当谈到IE和想知道这是否是好的做法?

I have seen them mainly used for implementing different stylesheets when it comes to IE and would like to know if this is good practice?

在这种情况下,如果答案是是。然后,当开发网站是常见的地方使用两个单独的样式表来修复错误,例如为IE创建一个样式表,Firefox和Opera等?

In which case if the answer is 'Yes'. Then when developing a site is it 'common place' to use two separate stylesheets to fix bugs, for example create one stylesheet for IE and one for Firefox, Opera etc?

提前感谢。

推荐答案

条件式注释只有IE支持,据我所知,他们在浏览器中优雅地降级不支持他们(因为他们看起来像一个正常的评论)。一般的共识是,如果你使用它来打击另一个非标准的浏览器功能(即在IE中肮脏的CSS支持),使用非标准的浏览器功能是可以的。所以你会发现,这是一个非常常见的解决方案来调整CSS。

Conditional comments are only supported by IE, as far as I know, and they gracefully downgrade in browsers that don't support them (since they look like a normal comment). The general consensus is that it's OK to use a non-standard browser feature if you're using it to combat another non-standard browser "feature" (i.e. the crappy support for CSS in IE). So you'll find that it's a very common solution for tweaking CSS.

这篇关于在HTML中使用条件注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆