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