MozTW 討論區 https://forum.moztw.org/ |
|
CSS: 規則重複定義問題 https://forum.moztw.org/viewtopic.php?f=13&t=10768 |
第 1 頁 (共 1 頁) |
發表人: | BobChao [ 2005-09-30, 17:42 ] |
文章主題 : | CSS: 規則重複定義問題 |
引言回覆: Explicitly re-defined style rule
In CSS stylesheets, order is important. If you define a rule and then you re-define the same rule, the last definition is used. #section { font-weight: bold; } .redtext { color: red; } /* other rules */ /* other rules */ /* other rules */ .redtext { font-weight: normal; } <div id="section"> This is bold, <span class="redtext"> this is normal and red,</span> and bold again </div> To avoid this kind of error, try to define rules only once for a certain selector, and group all rules belonging to that selector. 以上節錄自我目前在翻譯的文件,此部分說明重複定義規則者後發者勝,但舉出的例子似乎怪怪的?有人能告訴我他想說明什麼嗎? |
發表人: | Milx [ 2005-09-30, 20:07 ] |
文章主題 : | |
To avoid this kind of error, 我覺得他舉的例子不算error try to define rules only once for a certain selector, 作者可能也對CSS有些誤解 他可能認為 <span class="redtext"> this is normal and red,</span> 只有一個selector作用 事實上不是 and group all rules belonging to that selector. 這是作者建議(便於管理) |
發表人: | 訪客 [ 2005-09-30, 20:34 ] |
文章主題 : | |
BobChao 寫: 引言回覆: Explicitly re-defined style rule In CSS stylesheets, order is important. If you define a rule and then you re-define the same rule, the last definition is used. #section { font-weight: bold; } .redtext { color: red; } /* other rules */ /* other rules */ /* other rules */ .redtext { font-weight: normal; } <div id="section"> This is bold, <span class="redtext"> this is normal and red,</span> and bold again </div> To avoid this kind of error, try to define rules only once for a certain selector, and group all rules belonging to that selector. 以上節錄自我目前在翻譯的文件,此部分說明重複定義規則者後發者勝,但舉出的例子似乎怪怪的?有人能告訴我他想說明什麼嗎? 我猜他想說的是,之所以說是 error,「code 的作者」(不是這篇文章的作者!!)以為 #section 裏面的都會是 粗體字,但沒注意到後面又寫了 .redtext 的 rule 所以變成 normal。這時「這篇文章的作者」提醒後面寫的 rule 優先性比較高這一點,因為兩個 rule 沒有擺在一起所以沒考慮到。 這個例子好像有點怪怪的,應該舉同一個 class 或是 同一個 id 的同一個rule被指定兩次時,後面那次有效,這樣或許更清楚。也可能是我誤會他的意思,他想說即使是不同的 class 或 id,但事實上 span.redtext 也是在 div#section 的底下,原本應該從 #section 之 font-weight 的 rule,但因為 .redtext 也指定了 font-weight,所以應該以 .redtext 為準。 好複雜,希望有解釋清楚 |
發表人: | 訪客 [ 2005-09-30, 20:54 ] |
文章主題 : | |
Milx 寫: To avoid this kind of error,
我覺得他舉的例子不算error 就 css 本身來說,上面的 code 當然不算 error,因為都是合法的。 但是不是 error 得看作者心裏想要的。如果一個作者不熟悉 css,不知道這個規則,結果寫了如上的 code 之後發現和他所要的效果不同時,對他來說,這個 code 就是 error。接下來他因為這個「錯誤」的code 而學到 css 的規則,以後就可以避免,就不會再發生這樣的 error。 所以純粹看你站在哪個角度來想。 那篇文章的作者是站在一個學習中的讀者的角度來想,他當然就可以用 error 這個字眼。 |
發表人: | BobChao [ 2005-10-01, 00:07 ] |
文章主題 : | |
我的理解是,作者想請讀者把同個 selector 的所有特性全部集中一次宣告,除了便於管理之外,也是要避免這段的標題「重複定義」。 不過舉的例子真的好怪 沒辦法辨認出他的例子想表達什麼 如果晚定義的規則中有同樣的特性也就算了,偏偏又沒有 這樣整合起來「本來」就會同時套用 normal 跟 red 了 (try it, 我試過標準模式還是這樣) |
發表人: | 李某人 [ 2005-10-01, 00:22 ] |
文章主題 : | |
作者應該是想說明當兩個 selectors' specificity 一樣的時候, 在後面的會作用... 但例子肯定是舉錯了, 因為即使把 .redtext { font-weight: normal; } 放到 #section 的 declaration 之前, span element 裡的文字的 font-weight 還會是 normal 啊... |
發表人: | BobChao [ 2005-10-01, 00:25 ] |
文章主題 : | |
李某人 寫: 作者應該是想說明當兩個 selectors' specificity 一樣的時候, 在後面的會作用... 但例子肯定是舉錯了, 因為即使把 .redtext { font-weight: normal; } 放到 #section 的 declaration 之前, span element 裡的文字的 font-weight 還會是 normal 啊... 對啊... 我先改例子好了,不然這個東西翻譯不下去... 改成這樣大家覺得如何: 引言回覆: #section { font-weight: bold; }
.redtext { color: red; } /* other rules */ /* other rules */ /* other rules */ .redtext { color: green; } <div id="section"> 粗體、 <span class="redtext">正常紅字?</span> 又見粗體 </div> 或者,幫我建議一下吧 ![]() |
發表人: | 訪客 [ 2005-10-01, 00:32 ] |
文章主題 : | |
我覺得應該照原作者的。 就是這些 rule 都沒有重複,所以看起來好像沒有問題。但我想原作者他訴求的重點,就是這不容易發現的地方。原本在 section 裏應該要 bold,可是加上 redtext 後變成 normal,看起來像是 error。 當然他的解釋不是很清楚,不太明瞭他的建議實際指的是什麼。但如果只是同一個 rule 重複出現兩次,那問題就太簡單,不太像是在這要解釋的。 |
發表人: | coolcd [ 2005-10-01, 04:54 ] |
文章主題 : | |
hemiola 寫: 我覺得應該照原作者的。
就是這些 rule 都沒有重複,所以看起來好像沒有問題。但我想原作者他訴求的重點,就是這不容易發現的地方。原本在 section 裏應該要 bold,可是加上 redtext 後變成 normal,看起來像是 error。 當然他的解釋不是很清楚,不太明瞭他的建議實際指的是什麼。但如果只是同一個 rule 重複出現兩次,那問題就太簡單,不太像是在這要解釋的。 我也覺得不應該修改作者提出的例子。 假如對內容有意見的話,也許可以在旁邊加個譯者的註解或例子。 |
發表人: | 11 [ 2005-10-01, 07:01 ] |
文章主題 : | |
前面有人提到重點了, 我加點料...... 我想原作者是強調 "Explicitly" re-defined style rule, [解釋內容] 建議 define rules only once for a certain selector, and group all rules belonging to that selector. 就是把同一個 selector 的所有 rules 寫在同一個區塊, 而不要穿插在各處, 因為 In CSS stylesheets, order is important. f you define a rule and then you re-define the same rule, the last definition is used. 就是說由於 CSS 編寫的 order 關係到 cascading, 穿插在各處可能會考驗寫作者的記憶力, 導致 cascading 結果和預期不符的 error 為了要 avoid this kind of error, 所以說最好是 "Explicitly" re-defined style rule [例子] 請把它想像成個幾百行的文件,兩個 .redtext 之間隔了二頁, 代碼: #section { font-weight: bold; } .redtext { color: red; } /* other rules */ /* other rules */ /* other rules */ .redtext { font-weight: normal; } <div id="section"> This is bold, <span class="redtext"> this is normal and red,</span> and bold again </div> 他建議改為 代碼: #section { font-weight: bold; }
.redtext { color: red; font-weight: normal; } /* other rules */ /* other rules */ /* other rules */ <div id="section"> This is bold, <span class="redtext"> this is normal and red,</span> and bold again </div> 這樣可以明白地 (Explicitly) 知道 .redtext 不繼承或說重新定義了 (re-defined) #section 的樣式規則 (style rule) - "font-weight: bold" 寫在一起才不會忘了後面的 .redtext { font-weight: normal; }, 而誤以為 <span class="redtext"></span> 內也應該是 bold, 但結果和預期不同 結論-- 原作者的解釋和例子不合, 解釋內容說的 cascading order, 但例子卻是在說 inheritance, 此外,標題的 re- 也沒必要, 說重新定義有點奇怪, 直接說明白地定義樣式規則就好了 總而言之一句話, 原文所要表達的就是"寫在一起比較不會混亂" 報告完畢 |
發表人: | Milx [ 2005-10-01, 10:38 ] |
文章主題 : | |
不能寫信去問原作嗎?? |
發表人: | james [ 2005-10-01, 11:58 ] |
文章主題 : | |
哈,"Translator, Traitor"! 從不同的角度來看,翻譯是另類創作,完成品訴求為何才是重點。 該逐句翻譯(原例),或是意譯(改寫範例),存乎譯者之心。 建議不妨將兩個例子都擺上,加上譯者附註說明。 至於讀者讀後心得為何,本就見仁見智,即使是技術文件也是。 |
第 1 頁 (共 1 頁) | 所有顯示的時間為 UTC + 8 小時 |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |