10 useful HTML5 features (you may not be using)

One: <detail> tag ( provide on-demand details to users )

The <detail> tag is used in conjunction with the <summary> tag. The default is closed. Clicking will expand the content.

Example:

<details>
     <summary>Click Here to get the user details</summary>
         <table>
                <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>Location</th>
                    <th>Job</th>
                </tr>
                <tr>
                    <td>1</td>
                    <td>Adam</td>
                    <td>Huston</td>
                    <td>UI/UX</td>
                </tr>
          </table>
  </details>
看到它正常工作

Two: contenteditable (attributes that can be set on the element to make the content editable)

It can be used with DIV, P, UL and other elements. You must specify similar <element contenteditable="true|false">.

Note that if the contenteditableattribute is not set on the element, it will be inherited from its parent.

 Example:

<h2> Shoppping List(Content Editable) </h2>
 <ul class="content-editable" contenteditable="true">
     <li> 1. Milk </li>
     <li> 2. Bread </li>
     <li> 3. Honey </li>
</ul>

Three: map tag (can help define image mapping)

The map label and the <area>label together determine the clickable area. The clickable area can be any of rectangular, circular or polygonal areas. If no shape is specified, it will consider the entire image.

Example:

<div>
    <img src="circus.jpg" width="500" height="500" alt="Circus" usemap="#circusmap">

    <map name="circusmap">
        <area shape="rect" coords="67,114,207,254" href="elephant.htm">
        <area shape="rect" coords="222,141,318, 256" href="lion.htm">
        <area shape="rect" coords="343,111,455, 267" href="horse.htm">
        <area shape="rect" coords="35,328,143,500" href="clown.htm">
        <area shape="circle" coords="426,409,100" href="clown.htm">
    </map>
 </div>

Four: <mark> tag (mark to highlight any text content)

Example:

 <p> Did you know, you can <mark>"Highlight something interesting"</mark> just with a HTML tag? </p>

Five: data-* attributes (used to store custom data dedicated to pages or applications.)

Example:

<h2> Know data attribute </h2>
 <div 
       class="data-attribute" 
       id="data-attr" 
       data-custom-attr="You are just Awesome!"> 
   I have a hidden secret!
  </div>

 <button onclick="reveal()">Reveal</button>

Then in javascript

function reveal() {
   let dataDiv = document.getElementById('data-attr');
    let value = dataDiv.dataset['customAttr'];
   document.getElementById('msg').innerHTML = `<mark>${value}</mark>`;
}

Six: <output> tag (represents the result of the operation)

Usually, this element defines an area that will be used to display some calculated text

Example:

<form oninput="x.value=parseInt(a.value) * parseInt(b.value)">
   <input type="number" id="a" value="0">
          * <input type="number" id="b" value="0">
                = <output name="x" for="a b"></output>
</form>

Seven: <datalist> tag (specified pre-defined option list)

It provides a autocompletefeature that allows you to enter the required options in advance.

Example:

<form action="" method="get">
    <label for="fruit">Choose your fruit from the list:</label>
    <input list="fruits" name="fruit" id="fruit">
        <datalist id="fruits">
           <option value="Apple">
           <option value="Orange">
           <option value="Banana">
           <option value="Mango">
           <option value="Avacado">
        </datalist>
     <input type="submit">
 </form>

Eight: range (input type selected by a given slider range)

Example (slider):

<form method="post">
    <input 
         type="range" 
         name="range" 
         min="0" 
         max="100" 
         step="1" 
         value=""
         onchange="changeValue(event)"/>
 </form>
 <div class="range">
      <output id="output" name="result">  </output>
 </div>

Nine: <meter> tag (measure data within a given range)

Example:

<label for="home">/home/atapas</label>
<meter id="home" value="4" min="0" max="10">2 out of 10</meter><br>

<label for="root">/root</label>
<meter id="root" value="0.6">60%</meter><br>

Ten: input

Example:

<input type="password" 
            name="password" 
            id="password" 
            placeholder="6-20 chars, at least 1 digit, 1 uppercase and one lowercase letter" 
            pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$" autofocus required>

required: mark the input field as required;

autofocus: automatic focus;

pattern: regular expression verification;

 Color picker

<input type="color" onchange="showColor(event)">
<p id="colorMe">Color Me!</p>

 

Guess you like

Origin blog.csdn.net/baidu_39043816/article/details/108529848