有空時候把一些常見可能不是每一個人都知道的css小細節總結了下,共勉。css
衆多周知,line-height是行高的意思,咱們時常會使用相似line-height:24px;這樣的代碼來設置絕對的行高。可是當咱們的需求改變,字體大小變更的時候,可能咱們還須要再次改動行高,那麼如今咱們可使用直接設置數字來設置行高,當咱們使用純數字來設置行高的時候,它相對於的是字體大小的倍數,也就是說下面的h4其實設置的行高也是12*2px就是24px。這樣設置的好處是當咱們在改變字體大小的時候,行高會自動進行改變。html
p{ font-size:12px; line-height:24px; } h4{ font-size:12px; line-height:2; }
background-clip: border-box|padding-box|content-box;segmentfault
該屬性指定了背景在哪些區域能夠顯示,但與背景開始繪製的位置無關,背景的繪製的位置能夠出如今不顯示背景的區域,這時就至關於背景圖片被不顯示背景的區域裁剪了一部分同樣。簡單來講:它指定了背景能夠覆蓋到哪一個位置。瀏覽器
background-origin: padding-box|border-box|content-box;ssh
該屬性指定了背景從哪一個區域(邊框、補白或內容)開始繪製,但也僅僅能控制背景開始繪製的位置,你能夠用這個屬性在邊框上繪製背景,但邊框上的背景顯不顯示出來那就要由background-clip來決定了。簡單來講:它指定了背景從哪一個位置開始展現。字體
你們都會使用border-radius來製做圓角或者球形狀,可是不多有人知道它是能夠指定角度的水平和垂直半徑,只須要咱們使用 / 來分開兩個值。這樣的話咱們能夠輕鬆實現一個橢圓形。動畫
.div1{ width: 200px; height: 150px; border-radius: 100px/75px; background-color:#000; }
而且當咱們使用百分比進行值的設置的時候,他會基於元素自身的寬高進行解析,也就是說其實上面的代碼能夠這麼寫。url
.div1{ width: 200px; height: 150px; border-radius: 50%/50%;
/* border-radius: 50%; */ background-color:#000; }
在w3c咱們能夠了解到animation-delay 屬性定義動畫什麼時候開始。animation-delay 值以秒或毫秒計。spa
而且:它提示了咱們能夠用負值定義這個屬性,相似當咱們使用-2s定義這個屬性的時候,好像動畫開始的時候已經播放了兩秒。3d
咱們都會使用box-shadow來爲咱們的盒子加上陰影相似這樣:box-shadow:3px 3px 4px rgba(0,0,0,.3);
可是當咱們的需求是隻有一個方向有陰影的時候,可能咱們再加上一層結構使用溢出隱藏來實現。其實box-shadow有一個第四個個長度的參數,稱爲擴張半徑,而且咱們可使用負值來對咱們的模糊半徑進行反向抵消,咱們看這兩個效果。
.div1{ width: 200px; height: 150px;
border: 1px solid #ddd;
box-shadow: 0 5px 4px #000;
}
.div1{ width: 200px; height: 150px; border: 1px solid #ddd; box-shadow: 0 5px 4px -4px #000; }
這樣使用第四個長度參數,咱們就輕鬆實現了單側陰影。並且咱們還能夠想到對邊兩側陰影的實現
.div1{ width: 200px; height: 150px; border: 1px solid #ddd; box-shadow: 0 5px 4px -4px #000,0 -5px 4px -4px #000; }
三角形是在頁面中經常使用的一項。有時候咱們會切圖來作,可是其實相似模擬下拉的那種下拉咱們是可使用簡單的css來實現的,而且數學好的話,各類角度都不在話下。
i{ width: 0; height: 0; float: left; margin:20px; } .up { border-left: 20px solid transparent; border-right: 20px solid transparent; border-bottom: 40px solid #000; } .down { border-left: 20px solid transparent; border-right: 20px solid transparent; border-top: 40px solid #000; } .left { border-top: 20px solid transparent; border-bottom: 20px solid transparent; border-right: 40px solid #000; } .right { border-top: 20px solid transparent; border-bottom: 20px solid transparent; border-left: 40px solid #000; } .top-left { border-top: 40px solid #000; border-right: 40px solid transparent; } .top-right { border-top: 40px solid #000; border-right: 40px solid transparent; } .bottom-left { border-bottom: 40px solid #000; border-right: 40px solid transparent; } .bottom-right { border-bottom: 40px solid #000; border-right: 40px solid transparent; }
角度來的話從下面的截圖中就能夠了解了。三角形的角度。。。我這裏就很少說了。。。
這裏要說的是cursor的值可不只僅是pointer。咱們能夠根據不一樣的場景使用不一樣的光標,你們能夠嘗試下,下方來自w3c:
值 | 描述 |
---|---|
url | 需使用的自定義光標的 URL。 註釋:請在此列表的末端始終定義一種普通的光標,以防沒有由 URL 定義的可用光標。 |
default | 默認光標(一般是一個箭頭) |
auto | 默認。瀏覽器設置的光標。 |
crosshair | 光標呈現爲十字線。 |
pointer | 光標呈現爲指示連接的指針(一隻手) |
move | 此光標指示某對象可被移動。 |
e-resize | 此光標指示矩形框的邊緣可被向右(東)移動。 |
ne-resize | 此光標指示矩形框的邊緣可被向上及向右移動(北/東)。 |
nw-resize | 此光標指示矩形框的邊緣可被向上及向左移動(北/西)。 |
n-resize | 此光標指示矩形框的邊緣可被向上(北)移動。 |
se-resize | 此光標指示矩形框的邊緣可被向下及向右移動(南/東)。 |
sw-resize | 此光標指示矩形框的邊緣可被向下及向左移動(南/西)。 |
s-resize | 此光標指示矩形框的邊緣可被向下移動(南)。 |
w-resize | 此光標指示矩形框的邊緣可被向左移動(西)。 |
text | 此光標指示文本。 |
wait | 此光標指示程序正忙(一般是一隻表或沙漏)。 |
help | 此光標指示可用的幫助(一般是一個問號或一個氣球)。 |
如何簡單不增長元素和太多代碼的狀況下實現一個遮罩層(此方案遮罩層並不能添加事件)。
.div1{ position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100px; height: 100px; background-color:#fff; box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.8); }
steps()是一個timing function,容許咱們將動畫或者過渡分割成段,而不是從一種狀態持續到另外一種狀態的過渡。
steps 有兩個參數
第一個確定是分幾步執行完
第二個有兩個值
1.start 第一幀是第一步動畫結束
2.end 第一幀是第一步動畫開始
他在咱們作動畫的時候用處是十分大的,若是有興趣的同窗能夠移步【譯】css動畫裏的steps()用法詳解
我這裏本身也根據網上的內容作了個小demo:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> body{ font-family:'宋體'; } @keyframes typing{ from { width: 0; } } @keyframes caret{ 50%{ border-color: transparent; } } body{ text-align: center; } h1{ width: 12ch; overflow: hidden; white-space: nowrap; border-right: 0.5em solid; animation: typing 3s steps(12),caret 1s steps(1) infinite; } </style> </head> <body> <h1>hello world!</h1> </body> </html>
未完待續~~~