Details and summary tag compatibility issues

血红的双手。 提交于 2019-11-28 13:58:36

This is an old question, but there is still limited browser support for the details and summary tags. One blog post that I found to be useful was this: http://blog.teamtreehouse.com/use-details-summary-elements. It uses jquery for backward compatibility.

I use this to get it to work on all non-supporting browsers:

if(this.parentElement.getAttribute('open')!='open') 
  this.parentElement.setAttribute('open','open'); 
else this.parentElement.removeAttribute ('open'); 
return false;

details summary {display: block;}
details summary::before {content: "▸ ";}
details[open="open"] summary::before {content: "▾ ";}
details summary ~ * {
    display: none;
}
details[open] summary ~ * {
    display: block;
}
<details>
  <summary onclick="if(this.parentElement.getAttribute('open')!='open') this.parentElement.setAttribute('open','open'); else this.parentElement.removeAttribute ('open'); return false;">{{ item.title }}</summary>
  {{ item.content }}
</details>

Note that Firefox sets an empty 'open' attribute. You want to normalize that by setting this with javascript to 'open'.

No JS? No problem, you will have the default behaviour. JS will just try to take over the browsers implementation and set or remove the attribute. CSS will take over the showing and hiding (based on the 'open' attribute). The CSS rule perfectly emulates the normal and behaviour, and therefore does not influence/change or break it. Because the detail/summary implementation is now fully JS and CSS backed, it will also work on all non-supporting browsers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!