CSS+DIV——前端er必備基礎

來源:互聯網
上載者:User

標籤:web開發   css   div   

  

  B/S真是一個長見識的階段,認識了很多前端必備的語言,隨著時間的增加,本以為新聞發布系統中學到的那些我還不知道是什麼的東西,會早已沒了印象。但反而卻更加深刻了,當時還不知道什麼是CSS,就學會了寫CSS。還不是什麼是非同步通訊,就學會了用AjaX。當看到視頻中的經典架構時,才發現,這不就是新聞發布系統中用到的CSS+DIV麼!(⊙o⊙)哦,原來我早就會寫了!


一、為什麼是DIV+CSS


  看到這個搭配,我就在想為什麼是這樣的組合?Span不可以麼!直接用HTML不可以麼!一個很明確的目的:為了讓資料內容與資料格式分離,方便前端er開發和維護。想象一下,一個內鏈樣式表的語句

<span style="font-family:KaiTi_GB2312;font-size:18px;"><link href="(css樣式表)" rel="stylesheet" type="text/css" /></span>

  如果需要修改任何一個前端元素的樣式,只要在樣式表中去尋找ID或類別名就可以了,這無疑大大提高了開發的效率。


  還有一個問題就是為什麼Span不可以?SPAN和DIV的區別在於,DIV(division)是一個區塊層級元素,可以包含段落、標題、表格,乃至諸如章節、摘要和備忘等。而SPAN是行內元素,SPAN的前後是不會換行的,它沒有結構的意義,純粹是應用樣式,當其他行內元素都不合適時,可以使用SPAN。



二、一步步實現DIV+CSS


Step ONE:DIV分塊


  首先要考慮到網頁分為幾個展示部分,Banner和Footer是必備的,其他內容的展示就是個性的問題了,分配給相應的DIV塊。





Step Two:DIV定位——盒子模型


  用CSS樣式表給DIV定位,就要用到我們的盒子模型了,如它的名字,盒子是用來存放東西的,可以任意的挪動。當然更專業的詞,我們稱它為浮動。下面就是盒子模型的展示,margin、border、padding。如果你可以聯想到照相館牆上的畫面那就再好不過了!










Step Three:整體架構


  以下的代碼是第一張原型的詮釋,是一個很基礎的CSS+DIV的實現結果。其中用到了盒子浮動的效果,讓content模組和link模組各自向左右兩邊浮動。



<html><head><style type="text/css"><!--body {margin:0px;font-size:13px;font-family:Arial;} #container{position:relative;width:100%;}#banner{height:80px;border:1px solid #000000;text-align:center;background-color:#a2d9ff;padding:10px;margin-bottom:2px;}#content{float:left;text-align:center;padding-right:200px;/* 內容往回擠200px */}#links{float:right;width:200px;border:1px solid #000000;margin-left:-200px;/* 強行往左拉回200px */text-align:center;}#footer{clear:both;/* 不受float影響 */text-align:center;height:30px;border:1px solid #000000;}--></style><title>CSS排版</title><body><div id="container"><div id="banner">banner</div><div id="content"><div class="blog"><div class="date">date</div><div class="blogcontent">content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br>content content content content content content content content content content<br></div></div><div class="others">others</div></div><div id="links"><div class="calendarhead">links<br>links<br>links<br>links</div><div class="calendartable">links<br>links<br>links<br>links</div><div class="side">links<br>links<br>links<br>links</div><div class="syndicate">links<br>links<br>links<br>links</div><div class="friends">links<br>links<br>links<br>links</div></div><div id="footer">footer</div></div></body></html>



如下:





三、小結


  在有了CSS與DIV組合之後,網頁的載入變得輕鬆,因為資料與格式的分離,讓維護更加容易。搜尋效率和瀏覽效率的提高,會帶來很好的使用者體驗。So...CSS+DIV構成的如此簡潔的原始碼前台,是我們學習前端開發的必備基礎。





CSS+DIV——前端er必備基礎

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.