2013-05-09 23 views
7

我正在考慮在我的Bootstrap編輯器(Bootply.com)中整合LESS以符合Bootstrap customization best practices,並支持mixin。引導自定義:我爲什麼要使用LESS?

但是,我還沒有確定使用LESS而不是簡單的CSS覆蓋的具體優點(性能和其他)。看來最終LESS被編譯爲CSS。看起來LESS會在引入Bootstrap的新版本時引入更多的維護/重新編譯任務。

當前使用Bootply進行Bootstrap自定義是通過在'bootstrap.css'之後添加自定義'theme.css'完成的。所以,如果你想改變.navbar顏色我只想添加幾行,以「theme.css」像..

.navbar-custom .navbar-inner { 
    background-color:#444444; 
} 

然後標記的樣子:

<div class="navbar navbar-custom navbar-fixed-top">.. 

如果這是不是定製的最佳實踐,LESS如何改進它?

+2

只是爲了澄清:你問的是[一般LESS的好處](http://coding.smashingmagazine.com/2010/12/06/using-the-less-css-preprocessor-for-smarter- style-sheets /),還是在你的特定配置中使用LESS? – 2013-05-09 12:45:58

+0

我想兩者都有,但更多的是關於使用LESS專門用於Bootstrap.css自定義。 – ZimSystem 2013-05-09 12:48:12

回答

11

LESS摘要遠CSS混亂是這樣的:

background: #45484d; /* Old browsers */ 
background: -moz-linear-gradient(top, #45484d 0%, #000000 100%); /* FF3.6+ */ 
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#45484d), color-stop(100%,#000000)); /* Chrome,Safari4+ */ 
background: -webkit-linear-gradient(top, #45484d 0%,#000000 100%); /* Chrome10+,Safari5.1+ */ 
background: -o-linear-gradient(top, #45484d 0%,#000000 100%); /* Opera 11.10+ */ 
background: -ms-linear-gradient(top, #45484d 0%,#000000 100%); /* IE10+ */ 
background: linear-gradient(to bottom, #45484d 0%,#000000 100%); /* W3C */ 
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#45484d', endColorstr='#000000',GradientType=0); /* IE6-9 */ 

在你的情況下,導航欄有一個梯度,所以你不能簡單地改變背景顏色。如果你使用LESS,你可以選擇兩種顏色,並且在Bootstrap的CSS文件中的某個地方,看起來像上面這些亂七八糟的東西會自動更新。

+0

謝謝,那麼有沒有辦法使用LESS並將覆蓋編譯到單獨的'theme.css'文件中 - 或者只能通過自定義構建'bootstrap.css'來完成? – ZimSystem 2013-05-09 13:30:43

+1

您必須選擇使用Bootstrap作爲普通CSS或Bootstrap with LESS。你會在'LESS'文件中找到'.border-radius(@baseBorderRadius)'這樣的東西,在這個文件中插入值。看看[navbar.less](https://github.com/twitter/bootstrap/blob/ master/less/navbar.less)來查看我的意思。所以不行,使用Bootstrap時無法編譯爲單獨的文件。 – woz 2013-05-09 13:36:26

+0

好吧..我需要考慮進一步實施LESS。你的回答有助於澄清。 – ZimSystem 2013-05-10 02:20:13

相關問題