欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HTML5——HTML5新标签与特性

程序员文章站 2024-01-25 15:56:22
...

兼容性问题

HTML5——HTML5新标签与特性

文档类型设定

  • document
    • HTML: sublime 输入 html:4s
    • XHTML: sublime 输入 html:xt
    • HTML5 sublime 输入 html:5 !

字符设定

  • :HTML与XHTML中建议这样去写
  • :HTML5的标签中建议这样去写

常用新标签

w3c 手册中文官网 : http://w3school.com.cn/

  • header:定义文档的页眉 头部

  • nav:定义导航链接的部分

  • footer:定义文档或节的页脚 底部

  • article:定义文章。

  • section:定义文档中的节(section、区段)

  • aside:定义其所处内容之外的内容 侧边

    <header> 语义 :定义页面的头部  页眉</header>
    <nav>  语义 :定义导航栏 </nav> 
    <footer> 语义: 定义 页面底部 页脚</footer>
    <article> 语义:  定义文章</article>
    <section> 语义: 定义区域</section>
    <aside> 语义: 定义其所处内容之外的内容 侧边</aside>
    
  • datalist 标签定义选项列表。请与 input 元素配合使用该元素

    <input type="text" value="请输入明星" list="star"/>
    	<datalist id="star">
    		<option value="刘德华">刘德华</option>
    		<option value="刘若英">刘若英</option>
    		<option value="刘晓庆">刘晓庆</option>
    		<option value="戚薇">戚薇</option>
    		<option value="戚继光">戚继光</option>
    	</datalist>
    
  • fieldset 元素可将表单内的相关元素分组,打包 legend 搭配使用

    <fieldset>
        		<legend>用户登录</legend>  标题
        		用户名: <input type="text"><br /><br />
        		密 码: <input type="password">
    </fieldset>
    

新增的input type属性值:

类型 使用示例 含义
email <input type=“email”> 输入邮箱格式
tel <input type=“tel”> 输入手机号码格式
url <input type=“url”> 输入url格式
number <input type=“number”> 输入数字格式
search <input type=“search”> 搜索框(体现语义化)
range <input type=“range”> *拖动滑块
time <input type=“time”> 小时分钟
date <input type=“date”> 年月日
datetime <input type=“datetime”> 时间
month <input type=“month”> 月年
week <input type=“week”> 星期 年

常用新属性

属性 用法 含义
placeholder < input type=“text” placeholder=“请输入用户名”> 占位符 当用户输入的时候 里面的文字消失 删除所有文字,自动返回
autofocus < input type=“text” autofocus> 规定当页面加载时 input 元素应该自动获得焦点
multiple < input type=“file” multiple> 多文件上传
autocomplete < input type=“text” autocomplete=“off”> 规定表单是否应该启用自动完成功能 有2个值,一个是on 一个是off on 代表记录已经输入的值 1.autocomplete 首先需要提交按钮
2.这个表单您必须给他名字
required < input type=“text” required> 必填项 内容不能为空
accesskey < input type=“text” accesskey=“s”> 规定**(使元素获得焦点)元素的快捷键 采用 alt + s的形式

综合案例

HTML5——HTML5新标签与特性

<form action="">
  <fieldset>
    <legend>学生档案</legend>
    <label for="userName">姓名:</label>
    <input type="text" name="userName" id="userName" placeholder="请输入用户名"> <br>
    <label for="userPhone">手机号码:</label>
    <input type="tel" name="userPhone" id="userPhone" pattern="^1\d{10}$"><br>
    <label for="email">邮箱地址:</label>
    <input type="email" required name="email" id="email"><br>
    <label for="collage">所属学院:</label>
    <input type="text" name="collage" id="collage" list="cList" placeholder="请选择"><br>
    <datalist id="cList">
      <option value="前端与移动开发学院"></option>
      <option value="java学院"></option>
      <option value="c++学院"></option>
    </datalist><br>
    <label for="score">入学成绩:</label>
    <input type="number" max="100" min="0" value="0" id="score"><br>
   <form action="">
    <fieldset>
    	<legend>学生档案思密达</legend>
    	<label>姓名: <input type="text" placeholder="请输入学生名字"/></label> <br /><br />
    	<label>手机号: <input type="tel" /></label> <br /><br />
    	<label>邮箱: <input type="email" /></label> <br /><br />
    	<label>所属学院:  <input type="text" placeholder="请选择学院" list="xueyuan"/>
    	<datalist id="xueyuan">
    		<option>java学院</option>
    		<option>前端学院</option>
    		<option>php学院</option>
    		<option>设计学院</option>
    	</datalist>

    	<br /><br />

    	<label>出生日期:   <input type="date" /></label> <br /><br />
    	<label>成绩:  <input type="number" /></label> <br /><br />
    	<label>毕业时间:  <input type="date" /></label> <br /><br />
    	<input type="submit" />  <input type="reset" />
    </fieldset>
    </form>
    <label for="inTime">入学日期:</label>
    <input type="date" id="inTime" name="inTime"><br>
    <label for="leaveTime">毕业日期:</label>
    <input type="date" id="leaveTime" name="leaveTime"><br>
    <input type="submit">
  </fieldset>
</form>
相关标签: h5c3新特性