css - `content: ' '` 与 `content: none`

标签 css cross-browser

我在阅读 Eric Meyer 的 CSS reset 时看到了这个:

blockquote:before, blockquote:after,
q:before, q:after {
    /* ? */ content: '';
    /* ? */ content: none;
}

我假设某些浏览器支持 content: '' 和一些 content: none,是这样吗?哪些浏览器支持哪些?

最佳答案

Meyer 将那个版本的 blockquote/q 重置样式归功于 Paul Chaplin。

卓别林的 post关于主题包含以下样式 block ,注释很有帮助。

blockquote, q
{
    quotes: none;
}

/*
Safari doesn't support the quotes attribute, so we do this instead.
*/
blockquote:before, blockquote:after, q:before, q:after
{
    /*
    CSS 2; used to remove quotes in case "none" fails below.
    */
    content: "";
    /*
    CSS 2.1; will remove quotes if supported, and override the above.
    User-agents that don't understand "none" should ignore it, and
    keep the above value. This is here for future compatibility,
    though I'm not 100% convinced that it's a good idea...
    */
    content: none;
}

归根结底:大多数浏览器的当前版本仅支持 quotes: none 样式,这消除了使用 :before:after 的需要 选择器。奇怪的人是 Safari/WebKit,它不尊重 quotes: none。解决这个问题的下一个方法是使用 :before/:after 伪元素,但在撰写本文时,WebKit 不支持 content:也没有,所以 content: "" 是必需的。

然而,那篇文章是在 2008 年,而且是 quick test使用当前的 WebKit 浏览器(Safari 5.1 和 Chrome 12)显示 quotes: none 在两者上都可以正常工作。 content: none bug against WebKit由于某种原因仍然开放,而 bug for the quotes property最近关闭了。

所以,长话短说,额外的样式似乎是为了支持旧版本的 Safari(可能还有 Chrome)。确切地确定它们何时获得支持有点困难,但所有浏览器的当前版本似乎都可以很好地处理 quotes: none(和 content: none)。

关于css - `content: ' '` 与 `content: none`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6803250/

相关文章:

javascript - 如何检测浏览器的能力?

css - WordPress 链接悬停颜色

javascript - Google "reCaptcha"有时无法显示/呈现

javascript - 为什么屏幕变暗并且我的 Bootstrap 模式没有出现?

javascript - 从 Chrome 自动填充电子邮件后摆脱输入时的黄色填充

javascript - 与<div>空白</div>innerHTML是<div>空白</div>在Internet Explorer中,有没有办法获得文本节点的确切内容?

google-chrome - Chrome下加载资源失败

jquery - 浏览器之间的 SVG 单击事件处理有何不同?

css - 如何使用 XSL 在 XML 中的特定 td 中保留新行和空格

performance - 使用多个浏览器和版本测试站点性能