CSS Note
weight:100%
height:100%
- 沒有預設值,沒寫就是null
- height的百分比值需要父元素有一個有效的高度值才能起作用
-ex.
box-sizing:border-box
- 讓你不用手動加減就可以涵蓋padding+margin在原本容器尺寸
background-image
linear-gradient漸層
background: linear-gradient(方向/角度, 顏色1 位置(%數), 顏色2 位置(%數)....);)
- 要是方向沒寫的話,預設為由上往下,若填寫角度則由左下角為圓心順時針旋轉
- ex.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
position 定位
-
absolute(絕對定位)
- 使用
absolute
屬性定位的元素是以在他所處上層容器的相對位置,若沒有上層容器,則以body
(螢幕左上角)位置作為相對位置
- 上層元素要設定屬性
position:relative
- 當畫面在捲動時,有該屬性的元素還是會隨著頁面捲動。
-
fixed(固定定位)
- 相對於 瀏覽器視窗 來定位,即便頁面捲動,它還是會固定在相同的位置。
-
relative(相對定位)
- 會使其元素「相對地」調整其原本該出現的所在位置,做出調整。
- 例子,假設設定兩個帶有顏色的容器。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 若增加
relative
屬性後且增加距離原本元素top:100px
後。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
sticky (跟relative 很像)
- 只要內層元素設定屬性
sticky
就好,在設定top/left/right/ bottom,就可以表達距離外層元素多少距離,而且長度超過螢幕尺寸(有捲軸的產生),不論我們怎麼轉他都是黏在那邊
- 預設滿版,width: 100%
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
font-weight(文字體粗細)
Demo 傳送門
line-height
transition 動畫
- opacity .5s .5s //延長多久 delay多久
常見屬性
- transition-delay
- transition-duration
- transition-property
- transition-timing-function
- 可以跟transform一起搭配
例子
假設html 有一個容器,我們在css設定他碰到時容器會以2秒時間增長程式碼如下。
- 2D/3d transform
- 常見屬性:
- translate以原本容器所在處,往X或Y軸移動,
- scaleX/scaleY()
- rotate(角度) 讓容器原地旋轉多少角度,若角度值為負數,則逆時間旋轉,要是角度為負責代表逆時鐘旋轉。
transform:translate
z-index層
- 只有在設定position 的元素上會有效
- 設定值越高越前面,值可以為負數
- 檢查
- 被覆蓋的層(想要置頂的層)的position是否也為relative或者absolute
- 如果1成立,則判斷是否此層的z-index比誤覆蓋的層的z-index數值大
- 如果2成立,判斷是否此層的父級元素比誤覆蓋的層的z-index數值大
- 如果3成立,判斷是否此層的父級元素比誤覆蓋的層的父級層的z-index數值大
overflow
- 元素要是超出某一範圍時該怎麼辦
- 常見的值
- overflow:auto; //預設會自動使用捲軸
- overflow:visible; //顯示的文字或圖片會直接超出範圍,不使用捲軸。
- overflow:hidden; //自動隱藏超出的文字或圖片。
- overflow:scroll; //自動產生捲軸。
- overflow:inherit; //繼承自父元素的可見性。
css 選擇器- 子選擇器(選擇器之間使用>
大於符號)
選擇父元素的子元素,但不包括子元素的子元素
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →