標籤:
在一定程度上,css不能被視為一個節目。雖然和其他語言,它有自己的規範。編碼,但它的笨拙實在讓我失望。
不喜歡css是由於不管怎麼最佳化代碼。項目大到一定程式後。都會看上去一團亂。並且有時候一個bug的定位也要花去不少時間。直到我發現了less。突然感慨。css中的jquery大概就是它了。
less同意傳參數,同意定義變數,能夠把層疊的樣式組織得較為美觀,能夠少寫很多反覆代碼……這一切的優勢,讓我毫不猶豫地要去把它增加接下來的項目。
舉個範例:
css要這樣寫:
#header h1 { font-size: 26px; font-weight: bold;}#header p { font-size: 12px;}#header p a { text-decoration: none;}#header p a:hover { border-width: 1px;}
而less能夠這樣寫:
#header { h1 { font-size: 26px; font-weight: bold; } p { font-size: 12px; a { text-decoration: none; &:hover { border-width: 1px } } }}
css要這樣寫:
#menu a { color: #111; border-top: dotted 1px black; border-bottom: solid 2px black;}.post a { color: red; border-top: dotted 1px black; border-bottom: solid 2px black;}
而less能夠這樣寫:
.bordered { border-top: dotted 1px black; border-bottom: solid 2px black;}#menu a { color: #111; .bordered;}.post a { color: red; .bordered;}
以下是學習它的一些資料:
1、less.js:http://www.lesscss.net/#download-options
2、高速 新手教程:http://www.bootcss.com/p/lesscss/
3、在ie6/7/8下使用less。須要加上es5-shim.js。:https://github.com/yumucode/es5-shim
剛在ie6下測試,使用http://localhost/test/less/會抱錯,來不及查原因。而http://localhost/test/less/index.php則不會報錯。比較理想的做法是不讓瀏覽器執行less.js,而是在頭版輸出,把.less檔案轉化成.css檔。
著作權聲明:本文博主原創文章。部落格,未經同意不得轉載。
什麼時候css會見less