Skip to content

[css-display-3] Clarify whether display: contents applies to ::before and ::after #1345

Closed

Description

@emilio

I have a (probably bitrotted already) implementation for this in Blink, but I talked about this with @dbaron a while ago and asked me to file this in order to clarify it, given Gecko doesn't implement it.

Gecko always treats display: contents in ::before and ::after as display: inline. It's not clear to me whether display: contents in pseudo-elements is really useful at all, and the implementation is complex.

It's pretty much non-observable, except for cases like https://github.com/w3c/web-platform-tests/blob/master/css/css-display-3/display-contents-before-after-002.html (where you specify reset properties on the pseudo, like border).

I think it's nice for consistency, but I wouldn't be too sad if it didn't apply to these pseudo-elements.

Activity

  1. Loirooriol commented on May 10, 2017

    @Loirooriol
    Contributor

    It's not much clear, but browsers seem to believe that display: contents should join different texts into a single run of text (#1281). Then, in the following example, "FooBar" would be a single flex item:

    <div>Foo</div>
    div { display: flex; justify-content: space-between }
    div::after { content: 'Bar'; display: contents }

    So in this case whether ::before and ::after support display: contents or not is observable by other means than box-related properties on the pseudo-elements.

    I think display: contents should apply to these pseudo-elements.

  2. tabatkins commented on May 10, 2017

    @tabatkins
    Member

    As @Loirooriol points out, it definitely has an observable effect, and is straightforward to define. Basically, the following two bits of markup:

    <div><span>Foo</span>Bar</div>

    and

    <div>Bar</div>
    <style>div::before { content: "Foo"; }</style>

    ...should be completely indistinguishable as far as CSS is concerned. There is no reason for the two to diverge in any way.

    That said, I also wouldn't be too sad if we defined that it didn't work. It's just inconsistent and breaks a constant that has nicely applied to ::before and ::after previously.

  3. css-meeting-bot commented on May 24, 2017

    @css-meeting-bot
    Member

    The CSS Working Group just discussed https://github.com/w3c/csswg-drafts/issues/1345, and agreed to the following resolutions:

    • RESOLVED: display:contents applies to ::after and ::before
    The full IRC log of that discussion <myles> TOPIC: https://github.com//issues/1345
    <myles> Github topic: https://github.com//issues/1345
    <myles> s/write/right/
    <myles> fantasai: <restates the topic>
    <myles> fantasai: TabAtkins and i are leaning toward "yes" but we aren't particularly resolute
    <myles> fantasai: any opinions/
    <myles> fantasai: ?
    <myles> Rossen: it is unclear, if we say "no," what is observable?
    <myles> fantasai: you can put a border on ::after, and the border will disappear if you say display:contents
    <myles> fantasai: because the box will disappear
    <myles> Rossen: was this just an oversight?
    <myles> fantasai: just needed clarification
    <myles> Rossen: this works for us
    <myles> Rossen: objections?
    <myles> RESOLVED: display:contents applies to ::after and ::before
  4. tabatkins commented on Jul 5, 2017

    @tabatkins
    Member

    Closing as no change, because the WG decided to stick with it applying, and the effects of that just fall out of the definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions