本文介绍了使用Modernizr库,为什么要在html标记中添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释(因为github页面没有)为什么Modernizr认为需要将所有这些类名添加到HTML标记中?加载Modernizr后,它看起来像这样:

Can anyone explain (because the github page doesn't) why Modernizr feels the need to add all of those classnames to the HTML tag ? After loading Modernizr, it looks like this:

<!doctype html>
<html class=" js flexbox canvas canvastext webgl ~~~~ etc etc

我没有看到任何解释为什么它想这样做.Modernizr提供属性让我知道是否支持canvas(Modernizr.canvas == true?)。这些html类名是否添加了比这更容易的测试?

I see no explanation at all why it wants to do that. Modernizr provides properties to let me know whether for example canvas is supported (Modernizr.canvas == true?). Are those html classnames added for a test that's easier than that?

推荐答案

这些类名称应在CSS代码中使用,因此您可以添加后备样式,以防功能不受支持。来自modernizr docs页面的示例:

These class names are meant to be used in your CSS code, so you can add fallback styles in case a feature is unsupported. Example from modernizr docs page:

/* Simulated box shadow using borders: */
.box {
   border-bottom: 1px solid #666;
   border-right:  1px solid #777;
}
.boxshadow div.box {
   border: none;
   -webkit-box-shadow: #666 1px 1px 1px;
      -moz-box-shadow: #666 1px 1px 1px;
           box-shadow: #666 1px 1px 1px;
}

这篇关于使用Modernizr库,为什么要在html标记中添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:22