、定義
<meta> 標(biāo)簽提供關(guān)于 HTML 文檔的元數(shù)據(jù)。它不會顯示在頁面上,但是對于機(jī)器是可讀的。可用于瀏覽器(如何顯示內(nèi)容或重新加載頁面),搜索引擎(關(guān)鍵詞),或其他 web 服務(wù)。
2、作用
meta里的數(shù)據(jù)是供機(jī)器解讀的,告訴機(jī)器該如何解析這個頁面,還有一個用途是可以添加服務(wù)器發(fā)送到瀏覽器的http頭部內(nèi)容,例如我們?yōu)轫撁嬷刑砑尤缦耺eta標(biāo)簽:
瀏覽器的頭部就會包括這些:
只有瀏覽器可以接受這些附加的頭部字段,并能以適當(dāng)?shù)姆绞绞褂盟鼈儠r,這些字段才有意義。
3、meta的必需屬性和可選屬性
meta的必需屬性是content,當(dāng)然并不是說meta標(biāo)簽里一定要有content,而是當(dāng)有http-equiv或name屬性的時候,一定要有content屬性對其進(jìn)行說明。例如:
必需屬性
<meta name="keywords" content="HTML,ASP,PHP,SQL">
這里面content里的屬性就是對keywords進(jìn)行的說明,所以呢也可以理解成一個鍵值對吧,就是{keywords:"HTML,ASP,PHP,SQL"}。
可選屬性
在W3school中,對于meta的可選屬性說到了三個,分別是http-equiv、name和scheme。考慮到scheme不是很常用,所以就只說下前兩個屬性吧。
http-equiv
http-equiv屬性是添加http頭部內(nèi)容,對一些自定義的,或者需要額外添加的http頭部內(nèi)容,需要發(fā)送到瀏覽器中,我們就可以是使用這個屬性。在上面的meta作用中也有簡單的說明,那么現(xiàn)在再舉個例子。例如我們不想使用js來重定向,用http頭部內(nèi)容控制,那么就可以這樣控制:
<meta http-equiv="Refresh" content="5;url=http://blog.yangchen123h.cn" />
在頁面中加入這個后,5秒鐘后就會跳轉(zhuǎn)到指定頁面啦,效果可看W3school的例子
name
第二個可選屬性是name,這個屬性是供瀏覽器進(jìn)行解析,對于一些瀏覽器兼容性問題,name屬性是最常用的,當(dāng)然有個前提就是瀏覽器能夠解析你寫進(jìn)去的name屬性才可以,不然就是沒有意義的。還是舉個例子吧:
<meta name="renderer" content="webkit">
這個meta標(biāo)簽的意思就是告訴瀏覽器,用webkit內(nèi)核進(jìn)行解析,當(dāng)然前提是瀏覽器有webkit內(nèi)核才可以,不然就是沒有意義的啦。當(dāng)然看到這個你可能會有疑問,這個renderer是從哪里冒出來的,我要怎么知道呢?這個就是在對應(yīng)的瀏覽器的開發(fā)文檔里就會有表明的,例如這個renderer是在360瀏覽器里說明的。360瀏覽器內(nèi)核控制Meta標(biāo)簽說明文檔
常用meta標(biāo)簽大總結(jié)
接下來就是常用的meta標(biāo)簽大總結(jié)啦,我會盡可能的做到全
charset
charset是聲明文檔使用的字符編碼,解決亂碼問題主要用的就是它,值得一提的是,這個charset一定要寫第一行,不然就可能會產(chǎn)生亂碼了。
charset有兩種寫法
兩個都是等效的。
百度禁止轉(zhuǎn)碼
百度會自動對網(wǎng)頁進(jìn)行轉(zhuǎn)碼,這個標(biāo)簽是禁止百度的自動轉(zhuǎn)碼
<meta http-equiv="Cache-Control" content="no-siteapp" />
SEO 優(yōu)化部分
viewport
viewport主要是影響移動端頁面布局的,例如:
content 參數(shù):
各瀏覽器平臺
Microsoft Internet Explorer
Google Chrome
360瀏覽器
UC手機(jī)瀏覽器
UCBrowser_U3_API
QQ手機(jī)瀏覽器
Apple iOS
Google Android
App Links
最后——移動端常用的meta
在響應(yīng)式布局逐漸成為主流的今天,網(wǎng)頁或者app的流式布局已經(jīng)不算是一個新鮮的詞匯了。今天我要講的一個內(nèi)容也是跟頁面流式布局有關(guān),如何讓你的網(wǎng)頁實(shí)現(xiàn)完美的縮放?
我們可以很快速的寫出一個響應(yīng)式布局的頁面,首先看一下效果圖。
網(wǎng)頁布局
其中html部分的代碼如下:
html部分代碼
css中的item代碼為:
css代碼
通過以上代碼,完成上述的流式布局后,在我們改變?yōu)g覽器窗口大小時,div也會隨之進(jìn)行縮放。
But,你以為這就是我們想要的結(jié)果嗎?
當(dāng)然不是!在改變?yōu)g覽器窗口大小時,我們發(fā)現(xiàn)雖然div的寬度是進(jìn)行了縮放,但是高度卻沒變,因此div的寬高比并未保持原始比例,我們可以看下以下的效果。
縮放后寬高比
從上圖中可以很容易看出,縮放后的div寬高比比之前小很多,這并不是我們想要的結(jié)果。
我們需要達(dá)到的效果是在改變?yōu)g覽器窗口大小時,div也會隨之進(jìn)行等比例的縮放。
首先,可以使用Javascript代碼去實(shí)現(xiàn),這是沒有問題的。但是綁定Javascript的onresize事件,在拖拽時可能會出卡頓現(xiàn)象,體驗(yàn)不是很好。
接下來我們通過CSS來實(shí)現(xiàn)以上的效果。
使用的核心屬性是我們平時并不太注意的padding-bottom。
padding-bottom有一個很容易讓人忽略的特性是,當(dāng)取值為百分比形式時,其百分比的基數(shù)是父元素的寬度,而不是高度。
因此我們可以在不用給父元素設(shè)置高度的時候,就可以通過padding-bottom屬性確定當(dāng)前元素的高度。我們的做法如下。
將元素的height屬性設(shè)為0,通過padding-bottom屬性確定元素高度。
設(shè)置合理的padding-bottom值,例如上述的例子中,在寬度為21%時,如果需要高度是寬度的1.62倍,我們可以將padding-bottom取值為34%
修改后的CSS代碼如下。
修改后的CSS
修改后,我們再次調(diào)整瀏覽器窗口的大小,就會發(fā)現(xiàn)div是等比例的進(jìn)行縮放,完美達(dá)到了我們的要求。
修改后等比例縮放
在這里,可能會有人有疑問如果設(shè)置overflow:hidden;那么里面的文字會不會因?yàn)槌^height,就會被隱藏了?
答案是不會的,根據(jù)CSS2.1的規(guī)范,overflow只會對處于padding外面的內(nèi)容生效,即只有超出了 padding區(qū)域的內(nèi)容才會被overflow屬性隱藏掉。而在設(shè)置padding-bottom后,實(shí)際已經(jīng)決定了元素的height屬性,因此overflow:hidden;不會生效。
今天這篇文章主要講解了利用CSS完成頁面等比例縮放的最簡單方式,你學(xué)會了嗎?
用鼠標(biāo)改變元素的尺寸。
如需了解更多有關(guān) resizable 交互的細(xì)節(jié),請查看 API 文檔 可調(diào)整尺寸小部件(Resizable Widget)。
默認(rèn)功能
在任意的 DOM 元素上啟用 resizable 功能。通過鼠標(biāo)拖拽右邊或底邊的邊框到所需的寬度或高度。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 默認(rèn)功能</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable { width: 150px; height: 150px; padding: 0.5em; } #resizable h3 { text-align: center; margin: 0; } </style> <script> $(function() { $( "#resizable" ).resizable(); }); </script></head><body> <div id="resizable" class="ui-widget-content"> <h3 class="ui-widget-header">縮放(Resizable)</h3></div> </body></html>
查看演示
動畫
使用 animate
選項(xiàng)(布爾值)使縮放行為動畫化。當(dāng)該選項(xiàng)設(shè)置為 true 時,拖拽輪廓到所需的位置,元素會在拖拽停止時以動畫形式調(diào)整到該尺寸。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 動畫</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable { width: 150px; height: 150px; padding: 0.5em; } #resizable h3 { text-align: center; margin: 0; } .ui-resizable-helper { border: 1px dotted gray; } </style> <script> $(function() { $( "#resizable" ).resizable({ animate: true }); }); </script></head><body> <div id="resizable" class="ui-widget-content"> <h3 class="ui-widget-header">動畫</h3></div> </body></html>
查看演示
限制縮放區(qū)域
定義縮放區(qū)域的邊界。使用 containment
選項(xiàng)來指定一個父級的 DOM 元素或一個 jQuery 選擇器,比如 'document.'。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 限制縮放區(qū)域</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #container { width: 300px; height: 300px; } #container h3 { text-align: center; margin: 0; margin-bottom: 10px; } #resizable { background-position: top left; width: 150px; height: 150px; } #resizable, #container { padding: 0.5em; } </style> <script> $(function() { $( "#resizable" ).resizable({ containment: "#container" }); }); </script></head><body> <div id="container" class="ui-widget-content"> <h3 class="ui-widget-header">限制</h3> <div id="resizable" class="ui-state-active"> <h3 class="ui-widget-header">縮放(Resizable)</h3> </div></div> </body></html>
查看演示
延遲開始
通過 delay
選項(xiàng)設(shè)置延遲開始縮放的毫秒數(shù)。通過 distance
選項(xiàng)設(shè)置光標(biāo)被按下且拖拽指定像素后才允許縮放。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 延遲開始</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable, #resizable2 { width: 150px; height: 150px; padding: 0.5em; } #resizable h3, #resizable2 h3 { text-align: center; margin: 0; } </style> <script> $(function() { $( "#resizable" ).resizable({ delay: 1000 }); $( "#resizable2" ).resizable({ distance: 40 }); }); </script></head><body> <h3 class="docs">時間延遲 (ms):</h3><div id="resizable" class="ui-widget-content"> <h3 class="ui-widget-header">時間</h3></div> <h3 class="docs">距離延遲 (px):</h3><div id="resizable2" class="ui-widget-content"> <h3 class="ui-widget-header">距離</h3></div> </body></html>
查看演示
助手
通過設(shè)置 helper
選項(xiàng)為一個 CSS class,當(dāng)縮放時只顯示元素的輪廓。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 助手</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable { width: 150px; height: 150px; padding: 0.5em; } #resizable h3 { text-align: center; margin: 0; } .ui-resizable-helper { border: 2px dotted #00F; } </style> <script> $(function() { $( "#resizable" ).resizable({ helper: "ui-resizable-helper" }); }); </script></head><body> <div id="resizable" class="ui-widget-content"> <h3 class="ui-widget-header">助手</h3></div> </body></html>
查看演示
最大/最小尺寸
使用 maxHeight
、maxWidth
、minHeight
和 minWidth
選項(xiàng)限制 resizable 元素的最大或最小高度或?qū)挾取?/p>
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 最大/最小尺寸</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable { width: 200px; height: 150px; padding: 5px; } #resizable h3 { text-align: center; margin: 0; } </style> <script> $(function() { $( "#resizable" ).resizable({ maxHeight: 250, maxWidth: 350, minHeight: 150, minWidth: 200 }); }); </script></head><body> <div id="resizable" class="ui-widget-content"> <h3 class="ui-widget-header">放大/縮小</h3></div> </body></html>
查看演示
保持縱橫比
保持現(xiàn)有的縱橫比或設(shè)置一個新的縱橫比來限制縮放比例。設(shè)置 aspectRatio
選項(xiàng)為 true,且可選地傳遞一個新的比率(比如,4/3)。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 保持縱橫比</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable { width: 160px; height: 90px; padding: 0.5em; } #resizable h3 { text-align: center; margin: 0; } </style> <script> $(function() { $( "#resizable" ).resizable({ aspectRatio: 16 / 9 }); }); </script></head><body> <div id="resizable" class="ui-widget-content"> <h3 class="ui-widget-header">保持縱橫比</h3></div> </body></html>
查看演示
對齊到網(wǎng)格
對齊 resizable 元素到網(wǎng)格。通過 grid
選項(xiàng)設(shè)置網(wǎng)格單元的尺寸(以像素為單位的高度和寬度)。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 對齊到網(wǎng)格</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable { width: 150px; height: 150px; padding: 0.5em; } #resizable h3 { text-align: center; margin: 0; } </style> <script> $(function() { $( "#resizable" ).resizable({ grid: 50 }); }); </script></head><body> <div id="resizable" class="ui-widget-content"> <h3 class="ui-widget-header">網(wǎng)格</h3></div> </body></html>
同步縮放
通過點(diǎn)擊并拖拽一個元素的邊來同時調(diào)整多個元素的尺寸。給 alsoResize
選項(xiàng)傳遞一個共享的選擇器。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 同步縮放</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> #resizable { background-position: top left; } #resizable, #also { width: 150px; height: 120px; padding: 0.5em; } #resizable h3, #also h3 { text-align: center; margin: 0; } #also { margin-top: 1em; } </style> <script> $(function() { $( "#resizable" ).resizable({ alsoResize: "#also" }); $( "#also" ).resizable(); }); </script></head><body> <div id="resizable" class="ui-widget-header"> <h3 class="ui-state-active">縮放</h3></div> <div id="also" class="ui-widget-content"> <h3 class="ui-widget-header">同步縮放</h3></div> </body></html>
查看演示
文本框
可縮放的文本框。
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>jQuery UI 縮放(Resizable) - 文本框</title> <link rel="stylesheet" > <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" > <style> .ui-resizable-se { bottom: 17px; } </style> <script> $(function() { $( "#resizable" ).resizable({ handles: "se" }); }); </script></head><body> <textarea id="resizable" rows="5" cols="20"></textarea> </body></html>
視覺反饋
通過設(shè)置 ghost
選項(xiàng)為 true,可在縮放期間顯示一個半透明的元素,而不是顯示一個實(shí)際的元素。
*請認(rèn)真填寫需求信息,我們會在24小時內(nèi)與您取得聯(lián)系。