七个让你惊叹的HTML技巧

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

我们倾向于使用HTML与CSS、JavaScript等,使我们的网站或博客看起来更有吸引力,但你知道仅HTML就有很多实用的秘密,可能会派上用场,帮助你设计一个华丽的网站?

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

[[417995]]

技巧1. Image Maps

image map基本上是具有可点击区域的图像。我们可以使用该可点击区域链接到网页的其他部分、文档或新链接。

好吧,并不是每个人都知道<map>元素可以定义用户可以单击的图像区域。我们需要做的就是使用<area>元素并在<map>元素中提及其对应的 XY 坐标。

下面是一个例子,你的网站访问者可以在点击世界地图的不同大洲时了解你在全球的业务。

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

技巧2:Icon Adder

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

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

  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <title>Icon Adder</title> 
  5. <meta name="theme-color" content="green;"> 
  6. <link rel="icon" href="download.jpg" 
  7. type="image/x-icon"/> 
  8. <style> 
  9. .container { 
  10. text-align: left; 
  11. h1 { 
  12. color: darkred; 
  13. </style> 
  14. </head> 
  15. <body> 
  16. <div class="container"> 
  17. <h1>Hi, I am NISHI KASHYAP!!</h1> 
  18. <b>You can see the icon adder above in place of the favicon.</b> 
  19. </div> 
  20. </body> 
  21. </html> 

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

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

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

  1. <center> 
  2. <a href="" onmouseover="document.bgColor='turquoise'">D</a> 
  3. <a href="" onmouseover="document.bgColor='pink'">r</a> 
  4. <a href="" onmouseover="document.bgColor='blue'">a</a> 
  5. <a href="" onmouseover="document.bgColor='red'">g</a> 
  6. <a href="" onmouseover="document.bgColor='yellow'">Y</a> 
  7. <a href="" onmouseover="document.bgColor='green'">o</a> 
  8. <a href="" onmouseover="document.bgColor='white'">u</a> 
  9. <a href="" onmouseover="document.bgColor='teal'">r</a> 
  10. <a href="" onmouseover="document.bgColor='olivedrab'">M</a> 
  11. <a href="" onmouseover="document.bgColor='green'">o</a> 
  12. <a href="" onmouseover="document.bgColor='seagreen'">u</a> 
  13. <a href="" onmouseover="document.bgColor='magenta'">s</a> 
  14. <a href="" onmouseover="document.bgColor='fusia'">e</a> 
  15. <a href="" onmouseover="document.bgColor='purple'">O</a> 
  16. <a href="" onmouseover="document.bgColor='navy'">v</a> 
  17. <a href="" onmouseover="document.bgColor='green'">e</a> 
  18. <a href="" onmouseover="document.bgColor='white'">r</a> 
  19. <a href="" onmouseover="document.bgColor='royalblue'">L</a> 
  20. <a href="" onmouseover="document.bgColor='Skyblue'">e</a> 
  21. <a href="" onmouseover="document.bgColor='almond'">tt</a> 
  22. <a href="" onmouseover="document.bgColor='coral'">e</a> 
  23. <a href="" onmouseover="document.bgColor='brown'">r</a> 
  24. <a href="" onmouseover="document.bgColor='almond'">s</a> 
  25. <a href="" onmouseover="document.bgColor='coral'">To</a> 
  26. <a href="" onmouseover="document.bgColor='olivedrab'">C</a> 
  27. <a href="" onmouseover="document.bgColor='teal'">h</a> 
  28. <a href="" onmouseover="document.bgColor='pink'">a</a> 
  29. <a href="" onmouseover="document.bgColor='blue'">n</a> 
  30. <a href="" onmouseover="document.bgColor='red'">g</a> 
  31. <a href="" onmouseover="document.bgColor='yellow'">e</a> 
  32. <a href="" onmouseover="document.bgColor='green'">C</a> 
  33. <a href="" onmouseover="document.bgColor='olivedrab'">ol</a> 
  34. <a href="" onmouseover="document.bgColor='black'">or!</a> 
  35. </center> 

输出

技巧4:添加Title Tooltip

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

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

语法:

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

输出:

技巧5:语音识别

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

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

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

  1. <input type="text" x-webkit-speech /> 

让我给你看一个例子:

  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <title>Voice Recognition</title> 
  5. <style> 
  6. .container { 
  7. text-align: center; 
  8.  
  9. h1 { 
  10. color: darkred; 
  11. </style> 
  12. </head> 
  13.  
  14. <body> 
  15. <div class="container"> 
  16. <h1>Voice Recognition Field</h1> 
  17. <input type="text" x-webkit-speech> 
  18. <i><br><br>The above field  accepts the input as a Voice.<i> 
  19. </div> 
  20. </body> 
  21. </html> 

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

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

技巧6:隐藏字段

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

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

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

语法:

  1. <input type="hidden"> 

它是这样工作的:

  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <title>Hide Field</title> 
  5. <style> 
  6. h1 { 
  7. color: darkred; 
  8. body { 
  9. text-align: center; 
  10. </style> 
  11. </head> 
  12.  
  13. <body> 
  14. <h1>HIDE FIELD</h1> 
  15. <form action="#"> 
  16. <input type="hidden" id="myFile" value="1234"> 
  17. Name: <input type="text"> 
  18. <input type="submit" value="Submit"> 
  19. </form> 
  20. </body> 
  21. </html> 

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

输出:

技巧7:输入建议

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

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

  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <title>Input Suggestions</title> 
  5. </head> 
  6. <body> 
  7.  
  8. <h1>Choose the Continent</h1> 
  9. <input type="text" list="text_editors"> 
  10. <datalist id="text_editors"> 
  11. <option value="Africa"></option> 
  12. <option value="Asia"></option> 
  13. <option value="North America"></option> 
  14. <option value="South America"></option> 
  15. <option value="Antarctica"></option> 
  16. <option value="Europe"></option> 
  17. <option value="Australia"></option> 
  18. </datalist> 
  19. </body> 
  20. </html> 

输出:

 

责任编辑:赵宁宁 来源: 今日头条
相关推荐

2015-11-30 17:12:31

Git使用技巧

2011-02-22 10:23:34

2023-08-22 10:25:19

CSS动画网页

2023-10-04 17:41:39

编程习惯代码

2024-03-12 10:02:31

Python内存编程

2023-03-09 15:45:36

ES6编码技巧数组

2022-12-12 13:19:11

Vue3开发技巧

2023-03-19 16:02:33

JavaScrip技巧编程语言

2023-09-07 16:28:46

JavaScrip

2021-11-22 12:13:54

Linuxwget 命令

2012-03-30 10:03:27

HTML 5

2023-06-02 15:53:38

工具Python开发

2023-02-23 16:49:11

ES6技巧

2023-05-30 09:59:38

2018-05-24 08:47:15

数据存储技巧

2023-11-18 09:07:59

Go语言技巧

2023-11-06 11:32:46

CSS选择器作用域

2022-04-14 10:40:11

领导者IT团队远程团队

2012-04-04 12:57:37

HTML5

2012-03-30 09:45:07

WEBHTML5
点赞
收藏

51CTO技术栈公众号