a标签的用法
a标签是HTML中很常用的标签
属性
- href(hyper reference)超链接
取值:
网址:
https://google.com
http://google.com
//google.com —> 无协议的网址,自动适应http,https,以后写链接就用//
路径:
绝对路径/a/b/c
相对路径a/b/c
index.html以及 ./index.html
伪协议:
javascript:代码;<a`` ``href``=``"javascript:;"``>``查看``</a>
可以生成a标签并且点击什么都不做
mailto:邮箱<a`` ``href``=``"mailto:xxx@gmail.com"``>发邮件给我</a>
tel:手机号<a`` ``href``=``"tel:13782475737"``>call我</a>
id:
href=#xxx<a`` ``href``=``"#xxx"``>``查看xxx``</a>
- target
内置名字
_blank:在新标签也打开<a`` ``href``=``"//baidu.com"`` ``target``=``"_blank"``>``超链接``</a>
_top:在最上打开
_parent:上一级窗口打开
_self:在当前页面打开<a`` ``href``=``"//baidu.com"`` ``target``=``"_self"``>``超链接``</a>
download(实际上没有用)
作用:不是打开页面,而是下载页面
问题:不是所有浏览器都支持,尤其是手机浏览器可能不支持
- rel=noopener
防止一个bug
作用
⚠️不要同时设置宽高,图片会变形
-
事件
监听图片是否加载成功,成功调用onload,失败调用onerror
onload
-
响应式
可替换元素
table标签的用法
相关的标签
table
- thread
- tbody
- tfoot
- tr:table row表的一行
- td:table data表的内容
- th:表头
相关的样式
table-layout
/* Keyword values */
table-layout: auto;
table-layout: fixed;
/* Global values */
table-layout: inherit;
table-layout: initial;
table-layout: unset;
border-collapse:合并border间隙
border-collapse: collapse;
- border-spacing:控制border之间的距离
border-spacing: 0;
例子1:
<body>
<table>
<thead>
<tr>
<th>英语</th>
<th>翻译</th>
</tr>
</thead>
<tbody>
<tr>
<td>hyper</td>
<td>超级</td>
</tr>
<tr>
<td>target</td>
<td>目标</td>
</tr>
<tr>
<td>reference</td>
<td>引用</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>空</td>
<td>空</td>
</tr>
</tfoot>
</table>
</body>
例子2:
<body>
<table>
<thead>
<tr>
<th></th>
<th>小红</th>
<th>小黄</th>
<th>小绿</th>
</tr>
</thead>
<tbody>
<tr>
<th>数学</th>
<td>79</td>
<td>56</td>
<td>65</td>
</tr>
<tr>
<th>语文</th>
<td>79</td>
<td>56</td>
<td>65</td>
</tr>
<tr>
<th>英语</th>
<td>79</td>
<td>56</td>
<td>65</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>总分</th>
<td>200</td>
<td>300</td>
<td>200</td>
</tr>
</tfoot>
</table>
</body>
form标签
作用
属性
- action:请求哪个页面,相当与src
autocomplete:自动建议用户名
<body>
<form action="/xxx" method="POST" autocomplete="on">
<input name="username" type="text" />
<input type="submit" />
</form>
</body>
method:用来控制get还是post
<form`` ``action``=``"/xxx"`` ``method``=``"POST"``>
⚠️form中必须要有type=”submit”,否则表单不能提交
input标签
作用
属性
类型type:button/submit/hidden/password/tel/text/value/number/name/radio(单选)/checkbox(多选)/file(上传文件)/textarea(多行文本框)/select(选择框)
事件
补充
访问HTML的时候别用双击文件的方法,会报错,用以下方法:
先安装http-server
yarn global add http-server
在终端输入
//-c表示缓存,-1表示不要缓存,.可以省略
http-server . -c-1
//或者缩写
hs -c-1
ctrl+单击网址即可在浏览器打开
另一种方法:
终端输入以下命令安装parcel
yarn global add parcel
输入命令
//后面是你的html文件的名字
parcel a-href.html
ctrl+单击网址打开
其他感想
学到了HTML中常用且重要的一些标签