本文爲部分翻譯文章,主要內容來自於:css-protips,筆者自身也添加了一些本身的小的Tips。css
:not()
屬性爲導航添加或者去除邊框傳統的方法是首先爲每一個li標籤添加標籤:html
/* add border */ .nav li { border-right: 1px solid #666; }
而後用last-child僞屬性做用於最後一個元素上:git
/* remove border */ .nav li:last-child { border-right: none; }
代替的方法應該是使用not
僞類去設置僅做用於部分元素的屬性:github
.nav li:not(:last-child) { border-right: 1px solid #666; }
body
添加line-height
屬性每每須要爲p
、h*
這類標籤單獨的添加行高屬性等,做爲替代的是能夠將它添加到body
屬性中,即:web
body { line-height: 1; }
經過這種方式文本類的元素能夠自動繼承該屬性。ide
任何一個元素的自動居中能夠使用flex屬性:svg
html, body { height: 100%; margin: 0; } body { -webkit-align-items: center; -ms-flex-align: center; align-items: center; display: -webkit-flex; display: flex; }
ul > li:not(:last-child)::after { content: ","; }
nth-child
屬性選擇元素li { display: none; } /* select items 1 through 3 and display them */ li:nth-child(-n+3) { display: block; }
.logo { background: url("logo.svg"); }
使用SVG做爲圖標能夠達到自動縮放的效果。flex
html { -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
max-height
在單純的CSS滑塊上.slider ul { max-height: 0; overlow: hidden; } .slider:hover ul { max-height: 1000px; transition: .3s ease; /* animate to max-height */ }
box-sizing
屬性html { box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; }
.calendar { table-layout: fixed; }
.list { display: flex; justify-content: space-between; } .list .person { flex-basis: 23%; }
a[href^="http"]:empty::before { content: attr(href); }
在iOS設備中,有時候Click事件會失效,須要設置一個專門的cursor屬性:優化
cursor:pointer
不過須要注意的是,這個屬性不可設置在Android設備上,若是設置在Android設備上,點擊的時候會出現一片藍色的背景。url
在iOS設備中,有時候若是彈出了鍵盤會致使輸入框失焦,即鍵盤上的內容沒法顯示在輸入框內,須要進行如下覆蓋:
* { -webkit-user-select: none; /* prevent copy paste */ }
變爲
input[type="text"] { -webkit-user-select: text; }