阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

7个让你惊叹的HTML技巧

280次阅读
没有评论

共计 6898 个字符,预计需要花费 18 分钟才能阅读完成。

导读 我们倾向于使用 HTML 与 CSS、JavaScript 等,使我们的网站或博客看起来更有吸引力。下面是一些很酷的 HTML 技巧,你可以用它来建立一个真正的动态网站。

下面是一些很酷的 HTML 技巧,你可以用它来建立一个真正的动态网站。

技巧 1. Image Maps

image map 基本上是具有可点击区域的图像。我们可以使用该可点击区域链接到网页的其他部分、文档或新链接。好吧,并不是每个人都知道。元素可以定义用户可以单击的图像区域。我们需要做的就是使用。元素并在元素中提及其对应的 XY 坐标。
下面是一个例子,你的网站访问者可以在点击世界地图的不同大洲时了解你在全球的业务。

<h1 style="text-align:center;">World Map</h1> 
<h4 style="text-align:center;">➤ Click on the dots in the map to get respective continent information</h4> 
<map name="continents_map"> 
<area shape="circle" coords="70,70,10" href="https://en.wikipedia.org/wiki/North_America"> 
<area shape="circle" coords="133,185,10" href="https://en.wikipedia.org/wiki/South_America"> 
<area shape="circle" coords="270,137,10" href="https://en.wikipedia.org/wiki/Africa"> 
<area shape="circle" coords="292,44,10" href="https://en.wikipedia.org/wiki/Europe"> 
<area shape="circle" coords="469,201,10" 
href="https://en.wikipedia.org/wiki/Australia"> 
<area shape="circle" coords="374,65,10" href="https://en.wikipedia.org/wiki/Asia"> 
<area shape="circle" coords="340,267,10" href="https://en.wikipedia.org/wiki/Antarctica"> 
</map> 
<figure style="text-align:center;"> 
<img usemap="#continents_map" src=https://bit.ly/2bgFrvL width="600px" /> 
</figure>

7 个让你惊叹的 HTML 技巧

技巧 2:Icon Adder

Icon Adder 基本上是指使用图标代替网站图标。

你只需要在 body 标签内的 link 标签中包含你的源图像文件的路径链接。

<!DOCTYPE html> 
<html> 
<head> 
<title>Icon Adder</title> 
<meta name="theme-color" content="green;"> 
<link rel="icon" href="https://www.linuxprobe.com/download.jpg" 
type="image/x-icon"/> 
<style> 
.container {text-align: left;} 
h1 {color: darkred;} 
</style> 
</head> 
<body> 
<div class="container"> 
<h1>Hi, I am NISHI KASHYAP!!</h1> 
<b>You can see the icon adder above in place of the favicon.</b> 
</div> 
</body> 
</html>

7 个让你惊叹的 HTML 技巧

技巧 3:允许用户选择背景颜色

使用此技巧,网站访问者只需将鼠标指针拖到书面文本的某些字母上即可更改其网页的背景颜色。

例子:在这种情况下,访问者可以通过将鼠标指针拖到“Drag Your Mouse Over Letters To Change Colors!”的文字上来改变颜色。

<center> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='turquoise'">D</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='pink'">r</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='blue'">a</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='red'">g</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='yellow'">Y</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='green'">o</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='white'">u</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='teal'">r</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='olivedrab'">M</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='green'">o</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='seagreen'">u</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='magenta'">s</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='fusia'">e</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='purple'">O</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='navy'">v</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='green'">e</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='white'">r</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='royalblue'">L</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='Skyblue'">e</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='almond'">tt</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='coral'">e</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='brown'">r</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='almond'">s</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='coral'">To</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='olivedrab'">C</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='teal'">h</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='pink'">a</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='blue'">n</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='red'">g</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='yellow'">e</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='green'">C</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='olivedrab'">ol</a> 
<a href="https://www.linuxprobe.com/skill-html.html" onmouseover="document.bgColor='black'">or!</a> 
</center>

输出:
7 个让你惊叹的 HTML 技巧

技巧 4:添加 Title Tooltip

Tooltip 是“HTML 中使用的一个概念,用于显示关于特定选定元素的一些额外信息”。

这个技巧基本上显示了当访问者将鼠标指针悬停在一个元素上时,网站创建者提供的额外信息。

语法:

<span title="Can you see this? This is the tooltip.:)">Drag Your Mouse Over Me!</span>

输出:
7 个让你惊叹的 HTML 技巧

技巧 5:语音识别

此功能类似于您在 Google 搜索文本框中看到的功能,其中语音识别功能可帮助您将句子放入输入字段。

当你使用语音识别输入时,在输入字段的边上会有一个小的麦克风图标显示,当访问者点击该语音图标时,他们的声音会被记录下来并作为用户的输入。

为此,您只需将 x-webkit-speech 属性添加到输入框。
一个例子:

<!DOCTYPE html> 
<html> 
<head> 
<title>Voice Recognition</title> 
<style> 
.container {text-align: center;} 
 
h1 {color: darkred;} 
</style>

</head> 
 
<body> 
<div class="container"> 
<h1>Voice Recognition Field</h1> 
<input type="text" x-webkit-speech> 
<i><br><br>The above field  accepts the input as a Voice.<i> 
</div> 
</body> 
</html>

输出,然而,在实时服务器中,你会看到这个:

7 个让你惊叹的 HTML 技巧
但当你从其他浏览器查看时,你也会看到输入栏中的麦克风图标,用户可以通过它输入语音。

技巧 6:隐藏字段

能够公开查看内部字段被 Reddit 士兵称为“编程恐怖”——毫无疑问,没有人想在自己的网站上体验这种恐怖。

但是这个问题可以通过使用 HTML 的隐藏字段特性来解决。

一个隐藏字段可以让 web 开发人员控制哪些数据可以被修改,哪些数据不能被修改,以及当用户提交表单时需要更新的记录。

它是这样工作的:

<!DOCTYPE html> 
<html> 
<head> 
<title>Hide Field</title> 
<style> 
h1 {color: darkred;} 
body {text-align: center;} 
</style> 
</head> 
 
<body> 
<h1>HIDE FIELD</h1> 
<form action="#"> 
<input type="hidden" id="myFile" value="1234"> 
Name: <input type="text"> 
<input type="submit" value="Submit"> 
</form> 
</body> 
</html>

从上面的代码中,结果输出将是一个访问者无法看到的隐藏字段。

输出:

<!DOCTYPE html> 
<html> 
<head> 
<title>Input Suggestions</title> 
</head> 
<body> 
 
<h1>Choose the Continent</h1> 
<input type="text" list="text_editors"> 
<datalist id="text_editors"> 
<option value="Africa"></option> 
<option value="Asia"></option> 
<option value="North America"></option> 
<option value="South America"></option> 
<option value="Antarctica"></option> 
<option value="Europe"></option> 
<option value="Australia"></option> 
</datalist> 
</body> 
</html>
技巧 7:输入建议

此功能基本上提供了一个预定义选项的下拉列表,使访问者更容易找到他们正在寻找的内容。

示例:下面的代码让访问者从下拉列表中找到不同大陆的名称,并将其用作输入。

<!DOCTYPE html> 
<html> 
<head> 
<title>Hide Field</title> 
<style> 
h1 {color: darkred;} 
body {text-align: center;} 
</style> 
</head> 
 
<body> 
<h1>HIDE FIELD</h1> 
<form action="#"> 
<input type="hidden" id="myFile" value="1234"> 
Name: <input type="text"> 
<input type="submit" value="Submit"> 
</form> 
</body> 
</html>

输出:

7 个让你惊叹的 HTML 技巧

阿里云 2 核 2G 服务器 3M 带宽 61 元 1 年,有高配

腾讯云新客低至 82 元 / 年,老客户 99 元 / 年

代金券:在阿里云专用满减优惠券

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2024-07-25发表,共计6898字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19350
评论数
4
阅读量
7963593
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
星哥带你玩飞牛NAS-11:咪咕视频订阅部署全攻略

星哥带你玩飞牛NAS-11:咪咕视频订阅部署全攻略

星哥带你玩飞牛 NAS-11:咪咕视频订阅部署全攻略 前言 在家庭影音系统里,NAS 不仅是存储中心,更是内容...
240 元左右!五盘位 NAS主机,7 代U硬解4K稳如狗,拓展性碾压同价位

240 元左右!五盘位 NAS主机,7 代U硬解4K稳如狗,拓展性碾压同价位

  240 元左右!五盘位 NAS 主机,7 代 U 硬解 4K 稳如狗,拓展性碾压同价位 在 NA...
零成本上线!用 Hugging Face免费服务器+Docker 快速部署HertzBeat 监控平台

零成本上线!用 Hugging Face免费服务器+Docker 快速部署HertzBeat 监控平台

零成本上线!用 Hugging Face 免费服务器 +Docker 快速部署 HertzBeat 监控平台 ...
安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装 Black 群晖 DSM7.2 系统安装教程(在 Vmware 虚拟机中、实体机均可)! 前言 大家好,...
安装并使用谷歌AI编程工具Antigravity(亲测有效)

安装并使用谷歌AI编程工具Antigravity(亲测有效)

  安装并使用谷歌 AI 编程工具 Antigravity(亲测有效) 引言 Antigravity...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸 前言 作为天天跟架构图、拓扑图死磕的...
浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍

浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍

浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍 前言 在 AI 自动化快速发展的当下,浏览器早已不再只是...
三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

  三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Andr...
还在找免费服务器?无广告免费主机,新手也能轻松上手!

还在找免费服务器?无广告免费主机,新手也能轻松上手!

还在找免费服务器?无广告免费主机,新手也能轻松上手! 前言 对于个人开发者、建站新手或是想搭建测试站点的从业者...
星哥带你玩飞牛NAS-14:解锁公网自由!Lucky功能工具安装使用保姆级教程

星哥带你玩飞牛NAS-14:解锁公网自由!Lucky功能工具安装使用保姆级教程

星哥带你玩飞牛 NAS-14:解锁公网自由!Lucky 功能工具安装使用保姆级教程 作为 NAS 玩家,咱们最...