我正在使用Windows的LESS編譯器WinLESS。在style.less
,我使用@import
指令匯入我768up.less
和1030up.less
等所述@import與編譯的@import在CSS中的好處
編譯style.css
有768up.less
和1030up.less
內容在線解析,例如:
style.less
@import "normalize.less";
/* base styling here */
@media only screen and (min-width: 768px) { @import "768up.less"; }
@media only screen and (min-width: 1030px) { @import "1030up.less"; }
style.css
/* imported normalize */
html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } /* etc */
/* base styling */
.wrap { margin: 0; padding: 0 5px; } /* etc */
/* imported 768up */
.wrap { padding: 0 20px; }
/* imported 1030up */
.wrap { padding: 0 30px; }
這是不是破壞了@import
與@media
混合的目的?我的意思是,style.css
的文件大小現在是所有導入的+編譯文件的總和。
即使瀏覽器由於屏幕尺寸較小而不會使用1030up
,它是否仍會完整下載style.css
?
不是編譯style.css
應該包含@import
指令不變,使style.css
變得更加輕便,簡單地指示瀏覽器如果@media
條件滿足檢索其他造型?
WinLESS編譯這些CSS文件對我來說錯了嗎?
理想情況下,我想看到以下內容:
/* normalize */
@import "normalize.css";
/* base styling */
.wrap { margin: 0; padding: 0 5px; } /* etc */
/* progressively enhance styling to accomodate larger screens */
@media only screen and (min-width: 768px) { @import "768up.css"; }
@media only screen and (min-width: 1030px) { @import "1030up.css"; }
請,如果我誤解的@import
整體概念,賜教!
關於你的答案,我有一個很好的理由將基礎樣式與較重的桌面樣式分開。有快速知道何時使用單獨文件或內聯代碼更高效嗎?例如,如果我的'768up.css'增加了120kb(縮小),並且對於3種字體(根據瀏覽器的綜合平均值爲150kb)還使用了@字體 - 面,它將如何發揮作用?對於手機,它下載'style.css'完整,並且不會使用80%的樣式。 – 2013-03-25 22:26:09
它確實聽起來像保持它們分裂的那些情況之一更好!我更新了我的答案。但要確定哪個更快,請使用Chrome的分析工具。 – 2013-03-25 22:33:08