亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

20個(gè)非常實(shí)用的CSS技巧

  發(fā)布時(shí)間:2016-06-08 17:12:57   作者:佚名   我要評(píng)論
這篇文章主要為大家詳細(xì)介紹了20個(gè)非常實(shí)用的CSS技巧,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了20個(gè)非常實(shí)用的CSS技巧,供大家參考,具體內(nèi)容如下

1. 黑白圖像

這段代碼會(huì)讓你的彩色照片顯示為黑白照片,是不是很酷?

CSS Code復(fù)制內(nèi)容到剪貼板
  1. img.desaturate {   
  2.     filter: grayscale(100%);   
  3.     -webkit-filter: grayscale(100%);   
  4.     -moz-filter: grayscale(100%);   
  5.     -ms-filter: grayscale(100%);   
  6.     -o-filter: grayscale(100%);   
  7. }   
  8.   

2. 使用 :not() 在菜單上應(yīng)用/取消應(yīng)用邊框

先給每一個(gè)菜單項(xiàng)添加邊框

CSS Code復(fù)制內(nèi)容到剪貼板
  1. /* add border */  
  2. .nav li {   
  3.   border-right1px solid #666;   
  4. }   
  5. ……然后再除去最后一個(gè)元素……   
  6.   
  7. // remove border /   
  8.   
  9. .nav li:last-child {   
  10.   border-rightnone;   
  11. }   
  12. ……可以直接使用 :not() 偽類來應(yīng)用元素:   
  13.   
  14. .nav li:not(:last-child) {   
  15.   border-right1px solid #666;   
  16. }   

這樣代碼就干凈,易讀,易于理解了。

當(dāng)然,如果你的新元素有兄弟元素的話,也可以使用通用的兄弟選擇符(~):

CSS Code復(fù)制內(nèi)容到剪貼板
  1. ..nav li:first-child ~ li {   
  2.   
  3.   border-left1px solid #666;   
  4. }   
  5.   

3. 頁面頂部陰影

下面這個(gè)簡單的 css3 代碼片段可以給網(wǎng)頁加上漂亮的頂部陰影效果:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. body:before {   
  2.           content"";   
  3.           positionfixed;   
  4.           top: -10px;   
  5.           left: 0;   
  6.           width: 100%;   
  7.           height10px;   
  8.     
  9.           -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);   
  10.           -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);   
  11.           box-shadow: 0px 0px 10px rgba(0,0,0,.8);   
  12.     
  13.           z-index: 100;   
  14. }   
  15.   

4. 給 body 添加行高

你不需要分別添加 line-height 到每個(gè)p,h標(biāo)記等。只要添加到 body 即可:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. body {   
  2.   line-height: 1;   
  3. }  

這樣文本元素就可以很容易地從 body 繼承。

5. 所有一切都垂直居中

要將所有元素垂直居中,太簡單了:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. html, body {   
  2.   height: 100%;   
  3.   margin: 0;   
  4. }   
  5.   
  6. body {   
  7.   -webkit-align-items: center;     
  8.   -ms-flex-align: center;     
  9.   align-items: center;   
  10.   display: -webkit-flex;   
  11.   display: flex;   
  12. }   
  13.   

看,是不是很簡單。

注意:在IE11中要小心flexbox。

6. 逗號(hào)分隔的列表

讓html列表項(xiàng)看上去像一個(gè)真正的,用逗號(hào)分隔的列表:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. ul > li:not(:last-child)::after {   
  2.   content",";   
  3. }   
  4.   

對(duì)最后一個(gè)列表項(xiàng)使用 :not() 偽類。

7. 使用負(fù)的 nth-child 選擇項(xiàng)目

在CSS中使用負(fù)的 nth-child 選擇項(xiàng)目1到項(xiàng)目n。

CSS Code復(fù)制內(nèi)容到剪貼板
  1. li {   
  2.   displaynone;   
  3. }   
  4.   
  5. /* select items 1 through 3 and display them */  
  6. li:nth-child(-n+3) {   
  7.   displayblock;   
  8. }   
  9.   

8. 對(duì)圖標(biāo)使用 SVG

我們沒有理由不對(duì)圖標(biāo)使用SVG:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .logo {   
  2.   backgroundurl("logo.svg");   
  3. }  

SVG對(duì)所有的分辨率類型都具有良好的擴(kuò)展性,并支持所有瀏覽器都回歸到IE9。這樣可以避開.png、.jpg或.gif文件了。

9. 優(yōu)化顯示文本

有時(shí),字體并不能在所有設(shè)備上都達(dá)到最佳的顯示,所以可以讓設(shè)備瀏覽器來幫助你:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. html {   
  2.   -moz-osx-font-smoothing: grayscale;   
  3.   -webkit-font-smoothing: antialiased;   
  4.   text-rendering: optimizeLegibility;   
  5. }   
  6.   

注:請(qǐng)負(fù)責(zé)任地使用 optimizeLegibility。此外,IE /Edge沒有 text-rendering 支持。

10. 對(duì)純 CSS 滑塊使用 max-height

使用 max-height 和溢出隱藏來實(shí)現(xiàn)只有CSS的滑塊:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .slider ul {   
  2.   max-height: 0;   
  3.   overlow: hidden;   
  4. }   
  5.   
  6. .slider:hover ul {   
  7.   max-height1000px;   
  8.   transition: .3s ease;   
  9. }   
  10.   

11. 繼承 box-sizing

讓 box-sizing 繼承 html:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. html {   
  2.   box-sizing: border-box;   
  3. }   
  4.   
  5. *, *:before, *:after {   
  6.   box-sizing: inherit;   
  7. }   
  8.   

這樣在插件或杠桿其他行為的其他組件中就能更容易地改變 box-sizing 了。

12. 表格單元格等寬

表格工作起來很麻煩,所以務(wù)必盡量使用 table-layout: fixed 來保持單元格的等寬:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .calendar {   
  2.   table-layoutfixed;   
  3. }   
  4.   

13. 用 Flexbox 擺脫外邊距的各種 hack

當(dāng)需要用到列分隔符時(shí),通過flexbox的 space-between 屬性,你就可以擺脫nth-,first-,和 last-child 的hack了:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .list {   
  2.   display: flex;   
  3.   justify-content: space-between;   
  4. }   
  5.   
  6. .list .person {   
  7.   flex-basis: 23%;   
  8. }   
  9.   

現(xiàn)在,列表分隔符就會(huì)在均勻間隔的位置出現(xiàn)。

14. 使用屬性選擇器用于空鏈接

當(dāng)a元素沒有文本值,但 href 屬性有鏈接的時(shí)候顯示鏈接:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. a[href^="http"]:empty::before {   
  2.   contentattr(href);   
  3. }   
  4.   

相當(dāng)方便。

15. 檢測鼠標(biāo)雙擊

HTML:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div class="test3">  
  2.   <span><input type="text" value=" " readonly="true" />  
  3.   <a href="http://renpingjun.com">Double click me</a></span>  
  4. </div>  
  5.   

CSS:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .test3 span {   
  2.   positionrelative;   
  3. }   
  4. .test3 span a {   
  5.   positionrelative;   
  6.   z-index: 2;   
  7. }   
  8. .test3 span a:hover, .test3 span a:active {   
  9.   z-index: 4;   
  10. }   
  11. .test3 span input {   
  12.   backgroundtransparent;   
  13.   border: 0;   
  14.   cursorpointer;   
  15.   positionabsolute;   
  16.   top: -1px;   
  17.   left: 0;   
  18.   width: 101%;  /* Hacky */  
  19.   height: 301%; /* Hacky */  
  20.   z-index: 3;   
  21. }   
  22. .test3 span input:focus {   
  23.   backgroundtransparent;   
  24.   border: 0;   
  25.   z-index: 1;   
  26. }   
  27.   

16. CSS 寫出三角形

利用border來寫三角形代碼,并且兼容IE6.

CSS Code復(fù)制內(nèi)容到剪貼板
  1. /* create an arrow that points up */  
  2. div.arrow-up {   
  3.   width:0px;   
  4.   height:0px;   
  5.   border-left:5px solid transparent;  /* left arrow slant */  
  6.   border-right:5px solid transparent/* right arrow slant */  
  7.   border-bottom:5px solid #2f2f2f/* bottom, add background color here */  
  8.   font-size:0px;   
  9.   line-height:0px;   
  10. }   
  11.     
  12. /* create an arrow that points down */  
  13. div.arrow-down {   
  14.   width:0px;   
  15.   height:0px;   
  16.   border-left:5px solid transparent;   
  17.   border-right:5px solid transparent;   
  18.   border-top:5px solid #2f2f2f;   
  19.   font-size:0px;   
  20.   line-height:0px;   
  21. }   
  22.     
  23. /* create an arrow that points left */  
  24. div.arrow-left {   
  25.   width:0px;   
  26.   height:0px;   
  27.   border-bottom:5px solid transparent;  /* left arrow slant */  
  28.   border-top:5px solid transparent/* right arrow slant */  
  29.   border-right:5px solid #2f2f2f/* bottom, add background color here */  
  30.   font-size:0px;   
  31.   line-height:0px;   
  32. }   
  33.     
  34. /* create an arrow that points right */  
  35. div.arrow-rightright {   
  36.   width:0px;   
  37.   height:0px;   
  38.   border-bottom:5px solid transparent;  /* left arrow slant */  
  39.   border-top:5px solid transparent/* right arrow slant */  
  40.   border-left:5px solid #2f2f2f/* bottom, add background color here */  
  41.   font-size:0px;   
  42.   line-height:0px;   
  43. }   
  44.   

17. CSS3 calc() 的使用

calc() 用法類似于函數(shù),能夠給元素設(shè)置動(dòng)態(tài)的值:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. /* basic calc */  
  2. .simpleBlock {   
  3.   width: calc(100% - 100px);   
  4. }   
  5.     
  6. /* calc in calc */  
  7. .complexBlock {   
  8.   width: calc(100% - 50% / 3);   
  9.   padding5px calc(3% - 2px);      margin-left: calc(10% + 10px);   
  10. }   
  11.   

18. 文本漸變

文本漸變效果很流行,使用 CSS3 能夠很簡單就實(shí)現(xiàn):

CSS Code復(fù)制內(nèi)容到剪貼板
  1. h2[data-text] {   
  2.   positionrelative;   
  3. }   
  4. h2[data-text]::after {   
  5.   contentattr(data-text);   
  6.   z-index: 10;   
  7.   color#e3e3e3;   
  8.   positionabsolute;   
  9.   top: 0;   
  10.   left: 0;   
  11.   -webkit-mask-image: -webkit-gradient(linear, left topleft bottombottom, from(rgba(0,0,0,0)), color-stop(50%, rgba(0,0,0,1)), to(rgba(0,0,0,0)));}   
  12.   

19. 禁用鼠標(biāo)事件

CSS3 新增的 pointer-events 讓你能夠禁用元素的鼠標(biāo)事件,例如,一個(gè)連接如果設(shè)置了下面的樣式就無法點(diǎn)擊了。

.disabled { pointer-events: none; }

20. 模糊文本

簡單但很漂亮的文本模糊效果,簡單又好看!

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .blur {   
  2.    colortransparenttext-shadow: 0 0 5px rgba(0,0,0,0.5);   
  3. }   
  4.   

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 提高CSS代碼效率的編寫技巧

    這篇文章主要為大家詳細(xì)介紹了提高CSS代碼效率的編寫技巧,告訴大家DIV+CSS如何編寫代碼才能更有效率,感興趣的小伙伴們可以參考一下
    2016-06-28
  • 使用CSS的pointer-events屬性實(shí)現(xiàn)鼠標(biāo)穿透效果的神奇技巧

    當(dāng)pointer-events的值設(shè)置為none之后,瀏覽器將不會(huì)獲得鼠標(biāo)在當(dāng)前位置的層上的點(diǎn)擊事件,而造成鼠標(biāo)穿透的效果!下面就來為大家展開講解一下使用CSS的pointer-events屬性實(shí)現(xiàn)
    2016-06-28
  • CSS 設(shè)置技巧(單位和值與樣式設(shè)置技巧)

    這篇文章主要介紹了CSS 設(shè)置技巧(單位和值與樣式設(shè)置技巧),需要的朋友可以參考下
    2016-06-07
  • CSS 高級(jí)技巧總結(jié)(必看)

    下面小編就為大家?guī)硪黄狢SS 高級(jí)技巧總結(jié)(必看)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-06-06
  • 必須掌握10個(gè)非常不錯(cuò)的CSS技巧

    這篇文章主要為大家分享了必須掌握10個(gè)非常不錯(cuò)的CSS技巧,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • 詳解CSS制作Web頁面條紋背景樣式的技巧

    通過CSS中的linear-gradient主要就能顯示出不同方向的條紋效果,這里我們就來詳解CSS制作Web頁面條紋背景樣式的技巧,需要的朋友可以參考下
    2016-05-31
  • CSS制作邊框效果的技巧總結(jié)

    邊框在Web頁面的內(nèi)容塊中非常常用,這里為大家整理了CSS制作邊框效果的技巧總結(jié),尤其是第三種方案的background-origin利用十分討巧,需要的朋友可以參考下
    2016-05-27
  • css布局小技巧分享(必看)

    下面小編就為大家?guī)硪黄猚ss布局小技巧分享(必看)。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-05-24
  • 20 個(gè) CSS 高級(jí)技巧匯總(推薦)

    使用技巧會(huì)讓人變的越來越懶,沒錯(cuò),我就是想讓你變懶。下面是我收集的20條CSS高級(jí)技巧,具體內(nèi)容詳情大家參考下本文
    2017-11-30

最新評(píng)論