html - if IE 上 html 的条件语句

标签 html internet-explorer conditional-statements

我知道 html 不是一种编程语言,但是有什么方法可以根据浏览器更改编写代码,做一些类似的事情:

<!--[if IE]>
   <section class="card-container">
    <div id="so1" class="card over"  data-direction="right">        
      <div class="front" >
         <h1></h1><br/><br/><br/>
            <h2>ie
            </h2>
            <h3></h3>
      </div>         
      <div class="back" style="background-color:#99ca3c;">
          <img src="images/fanc1.jpg" width ="100%;" height ="100%;" alt="">                    
      </div>         
    </div>
   </section>
<![endif]-->

如果不是,即

   <section class="card-container">
    <div id="so1" class="card over"  data-direction="right">        
      <div class="front" >
    <img src="images/fanc1.jpg" width ="100%;" height ="100%;" alt="">
      </div>         
      <div class="back" style="background-color:#99ca3c;">
            <h1></h1><br/><br/><br/>
            <h2>not ie
            </h2>
            <h3></h3>               
      </div>         
    </div>
   </section>

或者它使用 php 并回显特定 html 代码的唯一方法?

如你所见,我只需要根据浏览器切换前面或后面的内容

最佳答案

更新如果有人仍然访问此页面,想知道为什么 ie 定位不起作用。 IE 10 及以后版本不再支持条件注释。来自微软官网:

Support for conditional comments has been removed in Internet Explorer 10 standards and quirks modes for improved interoperability and compliance with HTML5.

详情请看这里:http://msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx

如果您迫切需要以 ie 为目标,您可以使用此 jquery 代码添加一个 ie 类,然后在您的 css 中使用 .ie 类以以 ie 浏览器为目标。

if ($.browser.msie) {
 $("html").addClass("ie");
}

关于html - if IE 上 html 的条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16310126/

相关文章:

JavaScript 函数在第二次调用时无法获取对 DOM 元素的引用

internet-explorer - Internet Explorer 忽略某些域上的 cookie(无法读取或设置 cookie)

Python,与条件数组相反

c++ - 初学者 C "=="总是评估为 false

html - whatsapp html 链接不适用于 iphone 8,chrome

javascript - 用javascript增加 float

php - 仅在 mysql 数据库中插入一次。

javascript - IE如何在新选项卡中打开blob对象

internet-explorer - IE 7透明PNG问题

mysql - Laravel 4.x,Eloquent 多重条件