Saturday, 23 May 2015

How to use Summary and Details Tags in HTML5

Here I'm trying to demonstrate through an example how we can use HTML5 summary and details tag.

.html

<div id="page-wrapper">
  <h1>Details and Summary Elements Demo</h1>
  
  <h2>Example #1: Order Information</h2>
  
  <!-- Specifying an 'open' attribute will make all the content visible when the page loads -->
  <details>
    <summary>Order #24892105</summary>
    
    <table>
      <tr>
        <th scope="row">Order Date</th>
        <td>30th May 2003</td>
      </tr>
      <tr>
        <th scope="row">Order Number</th>
        <td>#24892105</td>
      </tr>
      <tr>
        <th scope="row">Courier</th>
        <td>Buy N Large Postal</td>
      </tr>
      <tr>
        <th scope="row">Shipping Address</th>
        <td>
          P. Sherman,<br>
          42 Wallaby Way,<br>
          Sydney,<br>
          Australia
        </td>
      </tr>
      <tr>
        <th scope="row">Billing Address</th>
        <td>
          P. Sherman,<br>
          42 Wallaby Way,<br>
          Sydney,<br>
          Australia
        </td>
      </tr>
    </table>
  </details>
  
  <h2>Example #2: Controls</h2>
  <details>
    <summary>README.txt</summary>
    <ul>
      <li><a href="#">Open</a></li>
      <li><a href="#">Edit</a></li>
      <li><a href="#">Duplicate</a></li>
      <li><a href="#">Delete</a></li>
    </ul>
  </details>
  <details>
    <summary>Blog Post.md</summary>
    <ul>
      <li><a href="#">Open</a></li>
      <li><a href="#">Edit</a></li>
      <li><a href="#">Duplicate</a></li>
      <li><a href="#">Delete</a></li>
    </ul>
  </details>
  <details>
    <summary>Mike's Vacation Plans.md</summary>
    <ul>
      <li><a href="#">Open</a></li>
      <li><a href="#">Edit</a></li>
      <li><a href="#">Duplicate</a></li>
      <li><a href="#">Delete</a></li>
    </ul>
  </details>
  
  <h2>Example #3: Custom Marker</h2>
  <details id="custom-marker">
    <summary>Custom Marker</summary>
    <p>Here be some content... yarr!</p>
  </details>

</div>

.css

*, *:before, *:after {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

html {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 100%;
  background: #333;
  -webkit-font-smoothing: antialiased;
}

#page-wrapper {
  width: 640px;
  background: #FFFFFF;
  padding: 1em;
  margin: 1em auto;
  border-top: 5px solid #69c773;
  box-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

h1 {
  margin-top: 0;
}

h2 {
  margin: 1em 0;
  font-size: 1em;
}

details {
  border-radius: 3px;
  background: #EEE;
  margin: 1em 0;
}

summary {
  background: #333;
  color: #FFF;
  border-radius: 3px;
  padding: 5px 10px;
  outline: none;
}

/* Style the summary when details box is open */
details[open] summary {
  background: #69c773;
  color: #333;
}

/* Custom Markers */
#custom-marker summary {
  font-size: 17px;
  vertical-align: top;
}

#custom-marker summary::-webkit-details-marker {
  display: none;
}

#custom-marker summary:before {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  content: "";
  background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4621/treehouse-icon-sprite.png);
  background-repeat: no-repeat;
  background-position: 0 0;
}

#custom-marker[open] summary:before {
  background-position: -18px 0;
}


table {
  border: 0;
  width: 100%;
}

th, td {
  vertical-align: top;
  text-align: left;
  padding: 0.5em;
  border-bottom: 1px solid #E6E6E6;
}

th {
  width: 200px;
}

ul {
  list-style: none;
  margin: 0;
  padding: 10px;
}

li {
  display: inline;
  padding-right: 10px;
}

a {
  color: #08C;
  text-decoration: none;

}


demo

Using details and summary elements to mark up order data.

source : http://codepen.io/

No comments:

Post a Comment

Join US Our Community
×