隨著瀏覽器的發展 HTML5+CSS3 的使用也越來越廣泛,一直想學這個,想學那個折騰下來幾乎沒學到什么東西。工作經驗告訴我,要掌握一門技術,就需要在項目中去磨練,
所以我就準備開發一個手機端的BBS練練手,技術更新快,也要學的快,跟的上時代,才漲的了工資。
jQuery Mobile Phone Gap 等都是比較成熟的框架為什么我不用這些框架呢? 因為我考慮到底層的技術應用和練習 。
我的選擇是:Html5+css3+angularjs+jquery
HTML5+CSS3 負責UI布局
angularjs 負責數據請求與綁定
jquery 負責頁面動畫效果
webApi 負責服務端數據接口
如圖:
在head添加meta標簽name為viewport,content參數請看圖中的解釋:
頁面總共分為頭部、主體、和底部三大塊。 HTML結構如下:
步驟三、樣式的編寫
html{font-size: 100%;}//字體為瀏覽器默認大小 body{font-size: 1.0em;} //1em等于默認字體大小(比如瀏覽器默認字體大小為16px,1em就等于16px)
1、為了適應所有瀏覽器,單位都采用em或者百分比
2、頭部左邊的可愛圖片和右邊的發貼按鈕,使用float:left和float:right 左右定位,為了讓和中間的標題文字在一條直線上使用了 position:relative 加 top進行定位(圖片和文字一般都不在一條直線上)
header h3{background: url(/img/common/line1.png) ; background-repeat:repeat-x;height: 3em;line-height: 3em;margin: 0;padding: 0;color: white;width: 100%; text-align:center}header h3 img{ position:relative; top:0.8em; float:left; margin-left:0.5em}header h3 .action-write-msg { outline:none; position:relative; top:0.8em;float: right;text-align: center; height: 2.5em;color: #fff; line-height: 0.5em;font-size: .875rem;border: 1px solid #e86b0f;border-radius: 4px; padding: 0 1.5em;background-color: #ff8200; margin-right:0.5em}header h3 .action-write-msg:hover{background-color: #e86b0f}
主體部體非常重要,需要保證中間可以滾動并且底部一直在最下面
使用:
position: fixed;top:4em 使主體部分一直浮動在瀏覽器頂部向下4em位置, 可以保證懸浮了,但是高度還是有問題
height:calc(100% - 8em); 我們知道頭部是4em 底部也是4em 那主體部分高度就是 100%-8em
overflow-y:scroll 上下滾動
article{position: fixed; overflow-y:scroll; top:4em; width: 100%; height:calc(100% - 8em); }article>ul{text-align:center;}article>ul li{ display:inline-block; background:#fff; width:40%;height:8em; border-radius:10%; margin:0.5em;line-height:2em; border:solid #fff 0.2em }article>ul li:hover{ border:0.2em dashed red}article>ul li img{margin-top:1em}article>ul li .title{ font-weight:bold;}
footer a {color: #B4E0D0;text-decoration: underline;margin: 5px;}footer a.current{ text-decoration:none; color:#fff}footer { font-size:0.7em;background: url(/img/common/line1.png);position: absolute;height: 3.5em;line-height: 1.5em;margin: 0;padding-top:0.5em ;color: white;width: 100%;text-align: center;bottom: 0em;clear: both; background-repeat:repeat-x;}
步驟四、angular綁定數據
var layoutApp = angular.module('layoutApp', []);
layoutApp.controller('headController', function ($scope) { $scope.title = "(3)、html綁定
demo地址:
https://github.com/sunkaixuan/AutoLayout
。。待續
新聞熱點
疑難解答