当前位置: 代码网 > it编程>网页制作>Css > HTML5中一些酷炫又有趣的新特性代码整理汇总

HTML5中一些酷炫又有趣的新特性代码整理汇总

2024年05月15日 Css 我要评论
html5 是 hypertext markup language 5 的缩写,html5技术结合了html4.01的相关标准并革新,符合现代网络发展要求,在2008年正式发布。html5 由不同的技

html5 是 hypertext markup language 5 的缩写,html5技术结合了html4.01的相关标准并革新,符合现代网络发展要求,在2008年正式发布。html5 由不同的技术构成,其在互联网中得到了非常广泛的应用,提供更多增强网络应用的标准机。与传统的技术相比,html5 的语法特征更加明显,并且结合了svg的内容。

html5并非仅仅用来表示web内容,它将 web带入一个成熟的应用平台,在html5平台上,视频、音频、图象、动画,以及同电脑的交互都被标准化。

html5自初始版本(2008 年 1 月)以来,我们一直在使用它的几个功能。再次查看html5 功能列表。发现一些功能过去用得不多,但现在发现它们很有用。

一、详情标签

<details>标签向用户提供按需详细信息。如果您需要按需向用户显示内容,请使用此标签。默认情况下,小部件是关闭的。打开时,它会展开并显示其中的内容。

<summary>标签用于<details>为它指定一个可见的标题。

<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>

三、地图

<map>标签有助于定义图像映射。图像映射是其中包含一个或多个可点击区域的图像。地图标签带有一个<area>标签来确定可点击区域。可点击区域可以是这些形状、矩形、圆形或多边形区域之一。如果您不指定任何形状,它会考虑整个图像。

<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>

四、标记内容

使用<mark>标签突出显示任何文本内容。

<p> 你知道吗,你可以仅使用 html 标签 <mark>"突出显示有趣的东西"</mark></p>

使用 css 更改高亮颜色

mark {
  background-color: green;
  color: #ffffff;
}

五、data-* 属性

这些data-*属性用于存储页面或应用程序私有的自定义数据。存储的数据可用于 javascript 代码以创建进一步的用户体验。

data-* 属性由两部分组成:

属性名称不应包含任何大写字母,并且必须在前缀“data-”之后至少长一个字符
属性值可以是任何字符串

<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>

六、输出标签

<output>标签表示的运算的结果。通常,此元素定义将用于显示某些计算的文本输出的区域。

<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>

七、数据列表

<datalist>标签指定了一个预定义选项列表,并允许用户向其中添加更多选项。它提供了一项autocomplete功能,允许您通过预先输入获得所需的选项。

<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>  

八、范围(滑块)

range是给定滑块类型范围选择器的输入类型。

<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

使用<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>

提示不要将<meter>标签用于进度指示器类型的用户体验。我们有来自 html5的<progress>标签。

<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新特性代码内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com