【问题标题】:Modernizr CSS rule ignored by Safari (Mobile Safari as well)Safari 忽略了 Modernizr CSS 规则(Mobile Safari 也是如此)
【发布时间】:2012-10-14 06:15:11
【问题描述】:

我无法弄清楚为什么 Safari/Mobile Safari 会忽略一行代码,它使用 Modernizr 的 .generatedcontent 规则来隐藏使用 icomoon 的图标。您可以在http://importbible.com/ 上查看实时站点,图标位于页面底部。浏览器在 Chrome 上完美呈现。做了更多测试,Safari 5.1.2 失败,而 Safari 6.0.1 工作。运行 4.3 的 iPad 失败。有问题的行是:

.generatedcontent .icon-gplus, .generatedcontent .icon-facebook, .generatedcontent .icon-twitter, .generatedcontent .icon-feed, .generatedcontent .icon-youtube, .generatedcontent .icon-flickr, .generatedcontent .icon-deviantart, .generatedcontent .icon-tumblr, .generatedcontent .icon-share, .generatedcontent .icon-tag, .generatedcontent .icon-home, .generatedcontent .icon-news, .generatedcontent .icon-cart, .generatedcontent .icon-cart, .generatedcontent .icon-basket, .generatedcontent .icon-mail, .generatedcontent .icon-clock, .generatedcontent .icon-forward, .generatedcontent .icon-replay, .generatedcontent .icon-chat, .generatedcontent .icon-refresh, .generatedcontent .icon-magnifier, .generatedcontent .icon-zoomin, .generatedcontent .icon-expand, .generatedcontent .icon-cog, .generatedcontent .icon-trash, .generatedcontent .icon-list, .generatedcontent .icon-grid, .generatedcontent .icon-download, .generatedcontent .icon-globe, .generatedcontent .icon-link, .generatedcontent .icon-attachment, .generatedcontent .icon-eye, .generatedcontent .icon-star_empty, .generatedcontent .icon-star_half, .generatedcontent .icon-star, .generatedcontent .icon-heart, .generatedcontent .icon-thumb, .generatedcontent .icon-cancel, .generatedcontent .icon-left, .generatedcontent .icon-right { display: none !important; }

【问题讨论】:

  • 你是在告诉我计算的样式对于匹配选择器的任何元素都没有显示吗?
  • 我无法在 Safari 5.1.2 Mac 中复制此错误。使用 BetterSource Safari 扩展加载您的页面以在呈现后显示源代码,我在 标记中看到了预期的“生成内容”类。
  • @alexroper CSS 出现了,但是页面底部有双图标(社交媒体)吗?

标签: css safari mobile-safari modernizr


【解决方案1】:

如果没有别的,把它作为调试选项扔出去。 您是否尝试过为.icons 使用通配符?

[class*='icon-'] { display:none !important }

[class^='icon-'] { display:none !important }

编辑: 星期五您的页面超时,所以我无法查看它。今天我收到以下错误(Safari 5.1.2/MAC):

  1. XMLHttpRequest 无法加载 http://static.ak.fbcdn.net/rsrc.php/v2/yy/r/5SjacuFVbni.js。起源 http://www.facebook.com 不允许 访问控制允许来源。 oauth
  2. 加载资源失败: 服务器以 407 状态响应(代理身份验证 必填)//这可能是我的结局。

我在“连接”下看到 6 个图标。

我直接浏览到错误行 #1 中的 URL 没有问题(Safari 或 Chrome)。

【讨论】:

  • 感谢 Dawson,很抱歉花了这么长时间才回来查看。似乎 Safari 不喜欢超长的选择器。用答案中的那个替换它。
【解决方案2】:

看起来<span class="icon-facebook">1</span> 是不支持生成内容的浏览器的备份。我建议默认隐藏备份(通过 CSS),并让 javascript 为不支持生成内容的浏览器显示备份图标。要么使用 Modernizr 的“no-generatedcontent”类,要么使用 IcoMoon 提供的 IE7 javascript 文件。

使用 Modernizr:

.icon-facebook { display: none; }
.no-generatedcontent .icon-facebook {display: inline; }

或由 IcoMoon 提供的 lte-ie7.js 文件。使用这种方法,您不必使用额外的标记(只需使用 <span class="icon-facebook-b"> 而不使用备份 <span class="icon-facebook">1</span>)。

/* Use this script if you need to support IE 7 and IE 6. */

window.onload = function() {
    function addIcon(el, entity) {
        var html = el.innerHTML;
        el.innerHTML = '<span style="font-family: \'icomoon\'">' + entity + '</span>' + html;
    }
    var icons = {
            'icon-home' : '&#x21;',
            'icon-home-2' : '&#x22;',
            'icon-newspaper' : '&#x23;',
            'icon-pencil' : '&#x24;',
            'icon-pencil-2' : '&#x25;'
        },
        els = document.getElementsByTagName('*'),
        i, attr, html, c, el;
    for (i = 0; i < els.length; i += 1) {
        el = els[i];
        attr = el.getAttribute('data-icon');
        if (attr) {
            addIcon(el, attr);
        }
        c = el.className;
        c = c.match(/icon-[^\s'"]+/);
        if (c) {
            addIcon(el, icons[c[0]]);
        }
    }
};

【讨论】:

    【解决方案3】:

    现在 Chrome 可以正常显示页脚社交图标,但在 Safari 5.1.7 中根本没有图标。

    我注意到的另一件事是,多个 CSS 文件被应用了两次(缩小的和普通的)。见第 73 行:

    <link rel='stylesheet' type='text/css' media='screen' href="http://importbible.com/wp-content/plugins/bwp-minify/min/?f=wp-content/themes/import_bible_5.3/css/bs-responsive.css,wp-content/themes/import_bible_5.3/css/rating.css,wp-content/themes/import_bible_5.3/style.css&amp;f22064" />
    

    第 420-422 行:

    <link rel='stylesheet' id='bootstrap-rs-css'  href="http://importbible.com/wp-content/themes/import_bible_5.3/css/bs-responsive.css?f22064" type='text/css' media='screen' />
    <link rel='stylesheet' id='rating-css'  href="http://importbible.com/wp-content/themes/import_bible_5.3/css/rating.css?f22064" type='text/css' media='screen' />
    <link rel='stylesheet' id='style-css'  href="http://importbible.com/wp-content/themes/import_bible_5.3/style.css?f22064" type='text/css' media='screen' />
    

    看起来 Safari 在这个特殊问题上变得很疯狂。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-06
      • 1970-01-01
      • 2013-10-11
      • 2020-03-09
      • 2010-11-16
      • 1970-01-01
      • 2014-06-06
      • 2016-02-03
      相关资源
      最近更新 更多