W3C home > Mailing lists > Public > www-style@w3.org > April 2010

Re: Thoughts on implementing the HTML5 <details> element with pure CSS

From: Andrew Fedoniouk <news@terrainformatica.com>
Date: Wed, 7 Apr 2010 00:16:21 -0700
Message-ID: <726B5D1F58324601AB78FE402412248B@terra3>
To: "Maciej Stachowiak" <mjs@apple.com>, "www-style CSS" <www-style@w3.org>

From: "Maciej Stachowiak" <mjs@apple.com>
Sent: Tuesday, April 06, 2010 11:13 PM
To: "www-style CSS" <www-style@w3.org>
Subject: Thoughts on implementing the HTML5 <details> element with pure CSS

> Recently, I tried to make a mockup of the HTML5 <details> element  using 
> CSS and JavaScript. Here is a reference for <details>:
> <http://dev.w3.org/html5/spec/Overview.html#the-details-element>
> My intended rendering and behavior was to match the "disclosure  triangle" 
> control on Mac OS X, much like the illustrated example in  the HTML5 spec. 
> I found that there were only two missing features in  existing and 
> forthcoming CSS that blocked me from fully and generally  specifying the 
> rendering with just CSS:
> 1) I wanted a nice animation transition for expanding and collapsing  the 
> disclosure triangle. But <details> needs to size to its contents,  so 
> effectively I need to transition to and from a height of "auto".  CSS 
> Transitions to/from auto values are, I think not supported per  spec, and 
> are certainly not supported in the WebKit implementation.
> 2) I need the <summary> child of <details> to remain visible both when 
> expanded and collapsed, but have all the other contents appear or 
> disappear, including direct text node children of the <details>  element. 
> However, there is no way to address all of the children of  <details> 
> except the <summary> child with a CSS selector.
> If these two things were fixed, then I could implement the rendering  of 
> this element fully with CSS, with script or native code needed only  to 
> toggle the "open" attribute of the <details> element when the  <summary> 
> is clicked. Doing it that way would be really nice, because  it would 
> provide a natural way for authors to customize the look and  even the 
> specific transition animation used when expanding and  collapsing.
> It seems like there may be other situations where facilities along the 
> lines above are useful, so I thought I'd post about my experience here.

Below is "pure" CSS solution of such expanding/collapsing element.
CSS should have following features in order it to work :

1) behavior: checkbox;  - this declares the DOM element to behave as
       checkbox - click on the element simply switches :checked state on and 
       on that element.

2) visibility:collapse; on arbitrary DOM element.
        collapsed element takes no space but has known intrinsic dimensions.
        Thus height: auto has meaning for such elements.

3) It is nice to have :animating state so you will be able to say:
      visibility:visible; // while animating it still should be visible
      overflow-y:hidden;  // and clip content

And here is that sample (from HTMLayout SDK [1]):


      behavior: checkbox;

    caption + div


    caption:checked + div

      transition: height(quad-out,0.4s)

      visibility:visible; // while animating it still should be visible
      overflow-y:hidden;  // and clip content
  <script type="text/tiscript"></script>
  <h1>Extended transition property demo</h1>
  <p>Animation to auto value</p>

  <div style="width:50%;height:*;margin:4px *;">
    <caption>Click me!</caption>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
commodo consequat.
      Duis aute irure dolor in reprehenderit in voluptate velit esse cillum 
dolore eu fugiat
      nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt 
in culpa qui
      officia deserunt mollit anim id est laborum.

[1] http://www.terrainformatica.com/htmlayout/HTMLayoutDemo.zip (MS Windows 

Andrew Fedoniouk


Received on Wednesday, 7 April 2010 07:16:49 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:07:44 UTC