HTML5中一些酷炫又有趣的新特性代码整理汇总 |
HTML5 是 HyperText Markup Language 5 的缩写,HTML5技术结合了HTML4.01的相关标准并革新,符合现代网络发展要求,在2008年正式发布 。HTML5 由不同的技术构成,其在互联网中得到了非常广泛的应用,提供更多增强网络应用的标准机 。与传统的技术相比,HTML5 的语法特征更加明显,并且结合了SVG的内容 。 HTML5并非仅仅用来表示Web内容,它将 Web带入一个成熟的应用平台,在HTML5平台上,视频、音频、图象、动画,以及同电脑的交互都被标准化 。 HTML5自初始版本(2008 年 1 月)以来,我们一直在使用它的几个功能 。再次查看HTML5 功能列表 。发现一些功能过去用得不多,但现在发现它们很有用 。 一、详情标签该 该 <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> <tr> <td>2</td> <td>Bob</td> <td>London</td> <td>Machine Learning</td> </tr> <tr> <td>3</td> <td>Jack</td> <td>Australia</td> <td>UI Designer</td> </tr> <tr> <td>4</td> <td>Tapas</td> <td>India</td> <td>Blogger</td> </tr> </table> </details> 二、内容可编辑contenteditable是可以在元素上设置以使内容可编辑的属性 。它适用于 DIV、P、UL 等元素 。您必须指定它,例如,<element contenteditable="true|false"> 。 注意: 当contenteditable元素上没有设置属性时,它将从其父元素继承 。 <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> 三、地图该 <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" rel="external nofollow" > <area shape="rect" coords="222,141,318, 256" href="lion.htm" rel="external nofollow" > <area shape="rect" coords="343,111,455, 267" href="horse.htm" rel="external nofollow" > <area shape="rect" coords="35,328,143,500" href="clown.htm" rel="external nofollow" rel="external nofollow" > <area shape="circle" coords="426,409,100" href="clown.htm" rel="external nofollow" rel="external nofollow" > </map> </div> 四、标记内容使用 <p> 你知道吗,你可以仅使用 HTML 标签 <mark>"突出显示有趣的东西"</mark></p> 使用 css 更改高亮颜色 mark { background-color: green; color: #FFFFFF; } 五、data-* 属性这些data-*属性用于存储页面或应用程序私有的自定义数据 。存储的数据可用于 JavaScript 代码以创建进一步的用户体验 。
<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> <p id="msg"></p> <script> function reveal() { let dataDiv = document.getElementById('data-attr'); let value = dataDiv.dataset['customAttr']; //使用getAttribute()它们的完整 HTML 名称(即 data-custom-attr), //但标准定义了一种更简单的方法:使用dataset属性 。 document.getElementById('msg').innerHTML = `<mark>${value}</mark>`; } </script> 六、输出标签
<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> 七、数据列表
<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> 八、范围(滑块)
<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> 九、Meter使用 <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>
<label for="file">Downloading progress:</label> <progress id="file" value="32" max="100"> 32% </progress> 十、Inputs这部分是我们最熟悉的输入类型的用法,如文本、密码等 。输入类型的特殊用法很少 必需的将输入字段标记为必填字段 。 <input type="text" id="username1" name="username" required> 自动对焦通过将光标放在输入元素上自动提供焦点 。 <input type="text" id="username2" name="username"autofocus> 使用正则表达式验证您可以使用正则表达式指定模式来验证输入 。 <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}$"> 颜色选择器一个简单的颜色选择器 。 <input type="color" onchange="showColor(event)"> <p id="colorMe">Color Me!</p> 到此这篇关于HTML5中一些酷炫又有趣的新特性代码整理汇总的文章就介绍到这了,更多相关HTML5新特性代码内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持! |