2013-10-25

如何寫出網頁,寫出一個內容會依照裝置畫面大小而做比例縮放的網頁…(針對行動裝置為主) update(10/25)

最近寫一些網頁,手機用的…
但發現,寫出來的畫面字都很小,但內容明明就沒多少東西,為什麼它不能match到畫面大小上咧…

後來發現,是習慣問題,我習慣寫出來的東西用電腦去看…但現在行動裝置很多,在html結構上也不太一樣,尤其是html5…

現在,只要用行動裝置瀏覽網頁,最好在meta上加上

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
content都算是重點…尤其是inital-scale…

參考資料:http://hahapoem.blogspot.tw/2011/01/blog-post.html

update (10/25)
本來都是如上在使用,但後來自己在用chrome時開了console在看錯誤repost發現…雖然上面在某些程度上是正常執行的,但console會報錯…如下

Viewport argument value "device-width;" for key "width" is invalid, and has been ignored. Note that ';' is not a separator in viewport values. The list should be comma-separated.
Viewport argument value "1.0;" for key "initial-scale" was truncated to its numeric prefix. Note that ';' is not a separator in viewport values. 
The list should be comma-separated. Viewport argument value "1.0;" for key "maximum-scale" was truncated to its numeric prefix. Note that ';' is not a separator in viewport values. 
The list should be comma-separated. Viewport argument value "0;" for key "user-scalable" was truncated to its numeric prefix. Note that ';' is not a separator in viewport values. The list should be comma-separated.
後來找了一下資料才發現,其實在html的meta tag中,分號是代表結束,所以最好改用逗號…所以改成如下

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
參考資料:http://ralphwhitbeck.com/2012/javascript-error-viewport/

沒有留言: