HTML常用标签

135 阅读1分钟
  1. a 标签的用法 属性
href
    超链接(不要双击打开HTML)
        href的取值:
            网址  https://xxx 
                 http://xxx
                 //xxx ;
            路径 /a/b/c以及a/b/c,
                 index.html,/index.html;
            伪协议
                javascript:代码; 例如javascript:alert(1);
                mailto:邮箱
                tel:手机号
            id
                href=#xxx
target
    指定在哪个窗口打开链接
download
    下载链接(不常用)
rel=noopener
    防bug

作用

1.跳转外部页面
2.跳转内部锚点
3.跳转到邮箱或电话等等
  1. img 标签的用法
    作用:发出get请求,展示一张图片
    属性:
        alt--图片加载失败时的替换
        height--图片高度(永远不要让图片变形)
        width--图片宽度
        src--图片地址
    事件:
    onload/onerror
    <script>
    xxx.onload=function(){
    console.log(“图片加载成功”);};
    xxx.onerror=function(){
    console.log(“图片加载失败”);};
    </script>
    响应式--适应手机端
    img{max-width:100%;}
  1. table 标签的用法
<table>
    <thead></thead>--表头
    <tbody></tbody>--表格中的行
    <tfoot></tfoot>--表尾
    <th></th>--定义表头单元格
    <tr></tr>--定义表格中的行
    <td></td>--定义表格中的单元格,嵌套在<tr></tr>中
</table>

    table-layout:auto--按表格内容大小个性化定制
    table-layout:fixed--尽量平均
    border-collapse--可控制border是否合并
    border-spacing--控制border和border之间的距离
        常规表格形式:
            border-collapse:collapse;
            border-spacing:0;

  1. form标签
    作用:发送get或post请求,然后刷新页面
    属性:
        action--控制请求那个页面
        autocomplete--输入时给出智能建议
        method--控制用get或postl来请求
        target--控制提交到那个页面
    事件:
        onsubmit--用户点提交时触发
<input/>与<button></button>的区别:
   <button></button>里面可以放标签,<input/>不行