首页 > 解决方案 > html前缀命名空间冲突

问题描述

我目前有以下html prefix namespaces

<html lang="en" dir="ltr" prefix="content: http://purl.org/rss/1.0/modules/content/
dc: http://purl.org/dc/terms/ foaf: http://xmlns.com/foaf/0.1/
og: http://ogp.me/ns# rdfs: http://www.w3.org/2000/01/rdf-schema#
schema: http://schema.org/ sioc: http://rdfs.org/sioc/ns#
sioct: http://rdfs.org/sioc/types# skos: http://www.w3.org/2004/02/skos/core#
xsd: http://www.w3.org/2001/XMLSchema# ">

我正在阅读一些东西并遇到了这个:

<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->

以下是我的问题:

1./ 将此添加到我的 html 网页是否会干扰/与我拥有的当前前缀命名空间发生冲突?

2./对于说为什么在html声明前和声明后if (gte IE 9)有封闭注释的情况<!--><!--

3./我能用这种声明做什么?

标签: html

解决方案


  1. 您只能有一个<html>标签,但您可以将第一个示例中的属性添加到<html>第二个示例的标签中。你想达到什么目的?

  2. 您的第二个示例包含条件注释。它们仅受旧版本的 Internet Explorer 支持。其他浏览器会将它们视为普通的 HTML 注释 - 即它们会忽略它们。该示例的最后一行关闭了 HTML 标记之前的注释,以便所有非 IE 浏览器仍能看到该<html lang="en">标记。如果它改为写成

    <!--[if (gte IE 9)|!(IE)]><html lang="en"><![endif]-->
    

    <html>标签将在评论内,因此会被所有浏览器忽略。

  3. 您发布的代码的目的是将 IE 版本特定的类输出到<html>标签。它允许您编写针对特定 IE 版本的 CSS 声明,例如:

    body {
       background-color: white;
    }
    
    .ie7 body {
        background-color: red;
    }
    

    这将使除 IE7 用户之外的每个人的页面背景都是白色的,对于他们来说它将是红色的。

在实践中,这些类型的解决方案现在并不常用,除非您迫切需要支持 Microsoft 本身不再支持的 IE 版本。


推荐阅读