15個css常用技巧

15個css常用技巧

1、三角形列表項目符號

ul { margin: 0.75em 0; padding: 0 1em; list-style: none;}li:before {  content: ""; border-color: transparent #111; border-style: solid; border-width: 0.35em 0 0.35em 0.45em; display: block; height: 0; width: 0; left: -1em; top: 0.9em; position: relative;}

2、外部CSS3 盒陰影

#mydiv {  -webkit-box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.52); -moz-box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.52); box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.52);}

3、內部CSS3 盒陰影

#mydiv {  -moz-box-shadow: inset 2px 0 4px #000; -webkit-box-shadow: inset 2px 0 4px #000; box-shadow: inset 2px 0 4px #000;}

4、CSS3 斑馬線

tbody tr:nth-child(odd) { background-color: #ccc;}

5、強制出現垂直滾動條

html { height: 101% }

6、內容垂直居中

.container { min-height: 6.5em; display: table-cell; vertical-align: middle;} 

7、CSS3:全屏背景

html {  background: url('images/bg.jpg') no-repeat center center fixed;  -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;}

8、錨鏈接偽類

a:link { color: blue; }a:visited { color: purple; }a:hover { color: red; }a:active { color: yellow; }

9、為logo隱藏H1

h1 { text-indent: -9999px; margin: 0 auto; width: 320px; height: 85px; background: transparent url("images/logo.png") no-repeat scroll;}

10、自定義文本選擇

::selection { background: #e2eae2; }::-moz-selection { background: #e2eae2; }::-webkit-selection { background: #e2eae2; }

11、跨瀏覽器的透明

.transparent { filter: alpha(opacity=50); /* internet explorer */ -khtml-opacity: 0.5; /* khtml, old safari */ -moz-opacity: 0.5; /* mozilla, netscape */ opacity: 0.5; /* fx, safari, opera */}

12、新版清除浮動(2011)

.clearfix:before, .container:after { content: ""; display: table; }.clearfix:after { clear: both; }/* IE 6/7 */.clearfix { zoom: 1; }

13、典型的CSS清除浮動

.clearfix:after { content: ".";  display: block; clear: both; visibility: hidden; line-height: 0; height: 0; }.clearfix { display: inline-block; }html[xmlns] .clearfix { display: block; }* html .clearfix { height: 1%; }

14、製造模糊文本

想要讓文本模糊?可以使用color透明和text-shadow實現

.blurry-text { color: transparent; text-shadow: 0 0 5px rgba(0,0,0,0.5);}

15、CSS:表格列寬自適用

對於表格,當談到調整列寬時,是比較痛苦的。然後,這裡有一個可以使用的技巧:給td元素添加white-space: nowrap;能讓文本正確的換行

td { white-space: nowrap;}


分享到:


相關文章: