Like HTML, CSS is not a programming language. It's not a markup language either. CSS is a style sheet language. MDN What is CSS?
CSS的重要概念是聯級、權重、繼承,而這樣的設計是為了更加彈性的處理畫面,畢竟畫面主要是由使用者、作者、代理UA三者共同來決定,為了處理這個問題而產生的『彈性機制』。這邊引用了大量的原文,不做太多的翻譯,是為了讓事情簡單一點(稀釋太多,怕跑掉原汁原味)也貼心附上原文出處,想了解更多歡迎前往探險。然而這些解釋名詞,需要透過有操作幾次的經驗,才比較有感在供蝦密。如果還沒用過CSS這無疑是天書無誤!
CSS不同於程式語言的原因之一,因為畫面呈現的控制權,是由使用者、作者、代理UA裝置所決定的。如何跟各種裝置大小互動,是CSS很重要的事情!
W3C規範名詞解釋
Style sheet
A set of statements that specify presentation of a document.
Style sheets may have three different origins: author, user, and user agent. The interaction of these sources is described in the section on cascading and inheritance.
參考資料: W3C 3.1 Definitions
W3C規範名詞解釋
Style sheets may have three different origins: author, user, and user agent.Style sheets from these three origins will overlap in scope, and they interact according to the cascade.
The CSS cascade assigns a weight to each style rule.
When several rules apply, the one with the greatest weight takes precedence.
參考資料: W3C 6.4 The cascade
!important > animation> transition >inline style > id > class > tag > 繼承
<div>
, <p>
, <ul>
, <ol>
, <li>
, <header>
, <footer>
, <article>
W3C規範名詞解釋
Author
An author is a person who writes documents and associated style sheets. An authoring tool is a User Agent that generates style sheets.
User
A user is a person who interacts with a user agent to view, hear, or otherwise use a document and its associated style sheet. The user may provide a personal style sheet that encodes personal preferences.
User agent (UA)
A user agent is any program that interprets a document written in the document language and applies associated style sheets according to the terms of this specification. A user agent may display a document, read it aloud, cause it to be printed, convert it to another format, etc.
參考資料: W3C 3.1 Definitions
是指元素可以繼承其父元素的一些樣式屬性。例如,如果父元素設置了字體大小,那麼子元素可以繼承這個屬性,但是,不是所有的樣式屬性都可以繼承,例如邊框、背景等樣式屬性就不會繼承。
W3C規範名詞解釋
Inheritance
Some values are inherited by the children of an element in the document tree, as described above. Each property defines whether it is inherited or not.When inheritance occurs, elements inherit computed values. The computed value from the parent element becomes both the specified value and the computed value on the child.
參考資料:W3C 6.2 Inheritance
優先權部分對於「內部載入>外部載入」有幾個疑問想請教與分享
內部載入是指使用 <style>
標籤嗎?
外部載入是指使用 <link>
標籤嗎?
我本身使用上,沒有內外部的優先權,只有先後順序跟選取器的權重問題
意思是,大部分我們使用 CSS 時,幾乎都是先寫 <link>
再寫 <style>
所以會認為內部優先於外部
但實際上你把兩者順序對調後就會發現優先順序對調了,變成外部優先於內部喔
是Amos前輩大駕光臨!
謝謝指出
內部載入是指使用 <style>
標籤嗎?
外部載入是指使用 <link>
標籤嗎?
是的,原本的意思是如此。剛剛去實驗了,如Amos所說,只有前後問題,沒有內外之差!感謝分享