七個(gè)讓你驚嘆的HTML技巧
我們傾向于使用HTML與CSS、JavaScript等,使我們的網(wǎng)站或博客看起來(lái)更有吸引力,但你知道僅HTML就有很多實(shí)用的秘密,可能會(huì)派上用場(chǎng),幫助你設(shè)計(jì)一個(gè)華麗的網(wǎng)站?
下面是一些很酷的HTML技巧,你可以用它來(lái)建立一個(gè)真正的動(dòng)態(tài)網(wǎng)站。
技巧1. Image Maps
image map基本上是具有可點(diǎn)擊區(qū)域的圖像。我們可以使用該可點(diǎn)擊區(qū)域鏈接到網(wǎng)頁(yè)的其他部分、文檔或新鏈接。
好吧,并不是每個(gè)人都知道<map>area>元素并在<map>元素中提及其對(duì)應(yīng)的 XY 坐標(biāo)。
下面是一個(gè)例子,你的網(wǎng)站訪問(wèn)者可以在點(diǎn)擊世界地圖的不同大洲時(shí)了解你在全球的業(yè)務(wù)。
- <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>
技巧2:Icon Adder
Icon Adder基本上是指使用圖標(biāo)代替網(wǎng)站圖標(biāo)。
你只需要在body標(biāo)簽內(nèi)的link標(biāo)簽中包含你的源圖像文件的路徑鏈接。
- <!DOCTYPE html>
- <html>
- <head>
- <title>Icon Adder</title>
- <meta name="theme-color" content="green;">
- <link rel="icon" href="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>
技巧3:允許用戶選擇背景顏色
使用此技巧,網(wǎng)站訪問(wèn)者只需將鼠標(biāo)指針拖到書面文本的某些字母上即可更改其網(wǎng)頁(yè)的背景顏色。
例子:在這種情況下,訪問(wèn)者可以通過(guò)將鼠標(biāo)指針拖到“Drag Your Mouse Over Letters To Change Colors!”的文字上來(lái)改變顏色。
- <center>
- <a href="" onmouseover="document.bgColor='turquoise'">D</a>
- <a href="" onmouseover="document.bgColor='pink'">r</a>
- <a href="" onmouseover="document.bgColor='blue'">a</a>
- <a href="" onmouseover="document.bgColor='red'">g</a>
- <a href="" onmouseover="document.bgColor='yellow'">Y</a>
- <a href="" onmouseover="document.bgColor='green'">o</a>
- <a href="" onmouseover="document.bgColor='white'">u</a>
- <a href="" onmouseover="document.bgColor='teal'">r</a>
- <a href="" onmouseover="document.bgColor='olivedrab'">M</a>
- <a href="" onmouseover="document.bgColor='green'">o</a>
- <a href="" onmouseover="document.bgColor='seagreen'">u</a>
- <a href="" onmouseover="document.bgColor='magenta'">s</a>
- <a href="" onmouseover="document.bgColor='fusia'">e</a>
- <a href="" onmouseover="document.bgColor='purple'">O</a>
- <a href="" onmouseover="document.bgColor='navy'">v</a>
- <a href="" onmouseover="document.bgColor='green'">e</a>
- <a href="" onmouseover="document.bgColor='white'">r</a>
- <a href="" onmouseover="document.bgColor='royalblue'">L</a>
- <a href="" onmouseover="document.bgColor='Skyblue'">e</a>
- <a href="" onmouseover="document.bgColor='almond'">tt</a>
- <a href="" onmouseover="document.bgColor='coral'">e</a>
- <a href="" onmouseover="document.bgColor='brown'">r</a>
- <a href="" onmouseover="document.bgColor='almond'">s</a>
- <a href="" onmouseover="document.bgColor='coral'">To</a>
- <a href="" onmouseover="document.bgColor='olivedrab'">C</a>
- <a href="" onmouseover="document.bgColor='teal'">h</a>
- <a href="" onmouseover="document.bgColor='pink'">a</a>
- <a href="" onmouseover="document.bgColor='blue'">n</a>
- <a href="" onmouseover="document.bgColor='red'">g</a>
- <a href="" onmouseover="document.bgColor='yellow'">e</a>
- <a href="" onmouseover="document.bgColor='green'">C</a>
- <a href="" onmouseover="document.bgColor='olivedrab'">ol</a>
- <a href="" onmouseover="document.bgColor='black'">or!</a>
- </center>
輸出
技巧4:添加Title Tooltip
Tooltip是“HTML中使用的一個(gè)概念,用于顯示關(guān)于特定選定元素的一些額外信息”。
這個(gè)技巧基本上顯示了當(dāng)訪問(wèn)者將鼠標(biāo)指針懸停在一個(gè)元素上時(shí),網(wǎng)站創(chuàng)建者提供的額外信息。
語(yǔ)法:
- <span title="Can you see this? This is the tooltip.:)">Drag Your Mouse Over Me!</span>
輸出:
技巧5:語(yǔ)音識(shí)別
此功能類似于您在 Google 搜索文本框中看到的功能,其中語(yǔ)音識(shí)別功能可幫助您將句子放入輸入字段。
當(dāng)你使用語(yǔ)音識(shí)別輸入時(shí),在輸入字段的邊上會(huì)有一個(gè)小的麥克風(fēng)圖標(biāo)顯示,當(dāng)訪問(wèn)者點(diǎn)擊該語(yǔ)音圖標(biāo)時(shí),他們的聲音會(huì)被記錄下來(lái)并作為用戶的輸入。
為此,您只需將 x-webkit-speech 屬性添加到輸入框。
- <input type="text" x-webkit-speech />
讓我給你看一個(gè)例子:
- <!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>
輸出,然而,在實(shí)時(shí)服務(wù)器中,你會(huì)看到這個(gè):
但當(dāng)你從其他瀏覽器查看時(shí),你也會(huì)看到輸入欄中的麥克風(fēng)圖標(biāo),用戶可以通過(guò)它輸入語(yǔ)音。
技巧6:隱藏字段
能夠公開查看內(nèi)部字段被Reddit士兵稱為“編程恐怖”——毫無(wú)疑問(wèn),沒(méi)有人想在自己的網(wǎng)站上體驗(yàn)這種恐怖。
但是這個(gè)問(wèn)題可以通過(guò)使用HTML的隱藏字段特性來(lái)解決。
一個(gè)隱藏字段可以讓web開發(fā)人員控制哪些數(shù)據(jù)可以被修改,哪些數(shù)據(jù)不能被修改,以及當(dāng)用戶提交表單時(shí)需要更新的記錄。
語(yǔ)法:
- <input type="hidden">
它是這樣工作的:
- <!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>
從上面的代碼中,結(jié)果輸出將是一個(gè)訪問(wèn)者無(wú)法看到的隱藏字段。
輸出:
技巧7:輸入建議
此功能基本上提供了一個(gè)預(yù)定義選項(xiàng)的下拉列表,使訪問(wèn)者更容易找到他們正在尋找的內(nèi)容。
示例:下面的代碼讓訪問(wèn)者從下拉列表中找到不同大陸的名稱,并將其用作輸入。
- <!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>
輸出: