`内容:''` vs `内容:无`

发布于 2024-11-25 13:12:00 字数 274 浏览 0 评论 0原文

我正在阅读 Eric Meyer 的 CSS Reset 并看到了这一点:

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

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

I was reading through Eric Meyer's CSS reset and saw this:

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

I assume that some browsers support content: '' and some content: none, is this the case? And which browsers support which?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不放开 2024-12-02 13:12:00

迈耶将那个版本的 blockquote/q 重置样式归功于保罗·卓别林 (Paul Chaplin)。

卓别林关于该主题的帖子包含以下样式块,并附有有用的注释。

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 年发布的,并且使用当前的 WebKit 浏览器(Safari 5.1 和 Chrome 12)进行了快速测试 )表明 quotes: none 在两者上都可以正常工作。针对 WebKit 的 content: none 错误 仍然存在由于某种原因,虽然 quotes 属性的错误 最近已被关闭。

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

Meyer credits Paul Chaplin with that version of the blockquote/q reset styles.

Chaplin's post on the subject contains the following style block, helpfully annotated.

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;
}

To boil it down: current versions of most browsers simply support a quotes: none style, which eliminates the need to use the :before and :after selectors. The odd man out was Safari/WebKit, which didn't respect quotes: none. The next way to solve this was with the :before/:after pseudo-elements, but at the time of that writing, WebKit didn't support content: none either, so content: "" was required.

However, that post was in 2008, and a quick test with current WebKit browsers (Safari 5.1 and Chrome 12) shows that quotes: none works fine on both. The content: none bug against WebKit is still open for some reason, while the bug for the quotes property was closed fairly recently.

So, long story short, the extra styles appear to be there to support older versions of Safari (and possibly Chrome). It's a little more difficult to nail down exactly when they got support, but current versions of all browsers seem to deal with quotes: none (and content: none) just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文