日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
30個(gè)你應(yīng)該知道的實(shí)用CSS代碼片斷

CSS是大家在web開發(fā)中常用的語言,但是有時(shí)候使用非常不爽。某一個(gè)CSS可能應(yīng)用在不同的瀏覽器中行為不全一樣。所以大家得花很多時(shí)間來進(jìn)行調(diào)試。

成都創(chuàng)新互聯(lián)公司成立與2013年,先為珠暉等服務(wù)建站,珠暉等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為珠暉企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

幸運(yùn)的是,網(wǎng)絡(luò)上大家可以找到很多不錯(cuò)的CSS代碼片斷,能夠有效地幫助大家解決一般性的或者設(shè)計(jì)問題。這里我們收集了30個(gè)CSS的代碼片斷幫助大家調(diào)試。希望大家喜歡!

代碼

1. Chris Poteet’s CSS瀏覽器重置代碼

這個(gè)代碼能夠有效地幫助大家解決跨瀏覽器問題。雖然不支持IE6,但是對(duì)于這種美國占有率低于1%的瀏覽器,大家大可以放棄。

 
 
 
  1. /*
  2. Reset Default Browser Styles
  3. - Place first in the listing of external style sheets for cascading.
  4. - Be sure to explicitly set margin/padding styles.
  5. - Styles are not reset that have to do with display (block, inline) are not reset.
  6. By: Chris Poteet & various influences
  7. */
  8. * {
  9. vertical-align: baseline;
  10. font-family: inherit;
  11. font-style: inherit;
  12. font-size: 100%;
  13. border: none;
  14. padding: 0;
  15. margin: 0;
  16. }
  17. body {
  18. padding: 5px;
  19. }
  20. h1, h2, h3, h4, h5, h6, p, pre, blockquote, form, ul, ol, dl {
  21. margin: 20px 0;
  22. }
  23. li, dd, blockquote {
  24. margin-left: 40px;
  25. }
  26. dt {
  27. font-weight: bold;
  28. }
  29. table {
  30. border-collapse: collapse;
  31. border-spacing: 0;
  32. }

2. Eric Meyer’s CSS Reset

Eric的CSS代碼片斷可能是最受歡迎的代碼之一。甚至支持Blueprint CSS Framework.

 
 
 
  1. /* http://meyerweb.com/eric/tools/css/reset/
  2.    v2.0 | 20110126
  3.    License: none (public domain)
  4. */
  5. html, body, div, span, applet, object, iframe,
  6. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  7. a, abbr, acronym, address, big, cite, code,
  8. del, dfn, em, img, ins, kbd, q, s, samp,
  9. small, strike, strong, sub, sup, tt, var,
  10. b, u, i, center,
  11. dl, dt, dd, ol, ul, li,
  12. fieldset, form, label, legend,
  13. table, caption, tbody, tfoot, thead, tr, th, td,
  14. article, aside, canvas, details, embed,
  15. figure, figcaption, footer, header, hgroup,
  16. menu, nav, output, ruby, section, summary,
  17. time, mark, audio, video {
  18.     margin: 0;
  19.     padding: 0;
  20.     border: 0;
  21.     font-size: 100%;
  22.     font: inherit;
  23.     vertical-align: baseline;
  24. }
  25. /* HTML5 display-role reset for older browsers */
  26. article, aside, details, figcaption, figure,
  27. footer, header, hgroup, menu, nav, section {
  28.     display: block;
  29. }
  30. body {
  31.     line-height: 1;
  32. }
  33. ol, ul {
  34.     list-style: none;
  35. }
  36. blockquote, q {
  37.     quotes: none;
  38. }
  39. blockquote:before, blockquote:after,
  40. q:before, q:after {
  41.     content: '';
  42.     content: none;
  43. }
  44. table {
  45.     border-collapse: collapse;
  46.     border-spacing: 0;
  47. }

3. How to Create Multiple Borders in CSS3

非??岬姆绞絼?chuàng)建box陰影,允許你創(chuàng)建多個(gè)邊框

 
 
 
  1. box-shadow:
  2.     0 0 0 2px #000,
  3.     0 0 0 3px #999,
  4.     0 0 0 9px #fa0,
  5.     0 0 0 10px #666,
  6.     0 0 0 16px #fd0,
  7.     0 0 0 18px #000; 

4. Tucked Corners

CSS代碼允許你創(chuàng)建類似非??岬腉ravatar首頁效果

 
 
 
  1. div.tucked-corners {
  2.         background: #f6f6f6;
  3.         height: 380px;
  4.         margin: 50px auto;
  5.         padding: 10px;
  6.         position: relative;
  7.         width: 580px;
  8.         -webkit-box-shadow: 0 1px 7px hsla(0,0%,0%,.2);
  9.            -moz-box-shadow: 0 1px 7px hsla(0,0%,0%,.2);
  10.                 box-shadow: 0 1px 7px hsla(0,0%,0%,.2);
  11.     }
  12.     span.tucked-corners {
  13.         background: #c4453c;
  14.         display: block;
  15.         height: 380px;
  16.         position: relative;
  17.         width: 580px;
  18.         -webkit-box-shadow: inset 0 0 10px hsla(0,0%,0%,.25);
  19.            -moz-box-shadow: inset 0 0 10px hsla(0,0%,0%,.25);
  20.                 box-shadow: inset 0 0 10px hsla(0,0%,0%,.25);
  21.     }
  22.     /* Top Corner Effect */
  23.     .top-corners:after,
  24.     .top-corners:before {
  25.         background: #e6e6e6;
  26.         content: '';
  27.         height: 50px;
  28.         position: absolute;
  29.         top: -25px;
  30.         width: 100px;
  31.         z-index: 10;
  32.         -webkit-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
  33.            -moz-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
  34.                 box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
  35.     }
  36.     .top-corners:after {
  37.         left: -50px;
  38.         -webkit-transform: rotate(-45deg);
  39.            -moz-transform: rotate(-45deg);
  40.             -ms-transform: rotate(-45deg);
  41.              -o-transform: rotate(-45deg);
  42.                 transform: rotate(-45deg);
  43.     }
  44.     .top-corners:before {
  45.         right: -50px;
  46.         -webkit-transform: rotate(45deg);
  47.            -moz-transform: rotate(45deg);
  48.             -ms-transform: rotate(45deg);
  49.              -o-transform: rotate(45deg);
  50.                 transform: rotate(45deg);
  51.     }
  52.     /* Bottom Corner Effect */
  53.     .bottom-corners:after,
  54.     .bottom-corners:before {
  55.         background: #e6e6e6;
  56.         content: '';
  57.         height: 50px;
  58.         position: absolute;
  59.         bottom: -25px;
  60.         width: 100px;
  61.         -webkit-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
  62.            -moz-box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
  63.                 box-shadow: 0 6px 9px -8px hsla(0,0%,0%,.5);
  64.     }
  65.     .bottom-corners:after {
  66.         left: -50px;
  67.         -webkit-transform: rotate(-135deg);
  68.            -moz-transform: rotate(-135deg);
  69.             -ms-transform: rotate(-135deg);
  70.              -o-transform: rotate(-135deg);
  71.                 transform: rotate(-135deg);
  72.     }
  73.     .bottom-corners:before {
  74.         right: -50px;
  75.         -webkit-transform: rotate(135deg);
  76.            -moz-transform: rotate(135deg);
  77.             -ms-transform: rotate(135deg);
  78.              -o-transform: rotate(135deg);
  79.                 transform: rotate(135deg);
  80.     }

5. iPad-Specific CSS

修改一般的ipad屏幕布局

 
 
 
  1. @media only screen and (device-width: 768px) {
  2.   /* For general iPad layouts */
  3. }
  4. @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
  5.   /* For portrait layouts only */
  6. }
  7. @media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
  8.   /* For landscape layouts only */
  9. }

6. Style links depending on file format

修改外部鏈接,email鏈接,pdf鏈接的樣式

 
 
 
  1. /* external links */
  2. a[href^="http://"]{
  3.     padding-right: 20px;
  4.     background: url(external.gif) no-repeat center right;
  5. }
  6. /* emails */
  7. a[href^="mailto:"]{
  8. padding-right: 20px;
  9. background: url(email.png) no-repeat center right;
  10. }
  11. /* pdfs */
  12. a[href$=".pdf"]{
  13. padding-right: 20px;
  14. background: url(pdf.png) no-repeat center right;

#p#

7. Drop Caps

非常棒的跨瀏覽器代碼幫助你使得每段文字的第一個(gè)字母更加

 
 
 
  1. .firstcharacter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; }

明顯CSS3也可以,但是不支持IE9

 
 
 
  1. p:first-child:first-letter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; }

8. CSS Sticky Footer

CSS實(shí)現(xiàn)的置頂sticky頁腳效果,支持所有的主流瀏覽器包括chrome和IE8

CSS:

 
 
 
  1. /*
  2. Sticky Footer Solution
  3. by Steve Hatcher 
  4. http://stever.ca
  5. http://www.cssstickyfooter.com
  6. */
  7. * {margin:0;padding:0;} 
  8. /* must declare 0 margins on everything, also for main layout components use padding, not
  9. vertical margins (top and bottom) to add spacing, else those margins get added to total height
  10. and your footer gets pushed down a bit more, creating vertical scroll bars in the browser */
  11. html, body {height: 100%;}
  12. #wrap {min-height: 100%;}
  13. #main {overflow:auto;
  14.     padding-bottom: 150px;}  /* must be same height as the footer */
  15. #footer {position: relative;
  16.     margin-top: -150px; /* negative value of footer height */
  17.     height: 150px;
  18.     clear:both;} 
  19. /*Opera Fix*/
  20. body:before {/* thanks to Maleika (Kohoutec)*/
  21. content:"";
  22. height:100%;
  23. float:left;
  24. width:0;
  25. margin-top:-32767px;/* thank you Erik J - negate effect of float*/
  26. }
  27. /* IMPORTANT
  28. You also need to include this conditional style in the  of your HTML file to feed this style to IE 6 and lower and 8 and higher.
  29. */

HTML:

 
 
 
  1.     
  2.     
  • 9. Image Replacement Technique

    實(shí)用的圖片替換文字頁面元素效果。

     
     
     
    1. a.replacement
    2. {
    3.   background: url(dotted-border.png) no-repeat;
    4.   height: 44px;
    5.   width: 316px;
    6.   display: block;
    7.   text-indent: -9999px;
    8.   overflow: hidden;  /*Add this line to the image replacement method*/
    9. }

    10. Set body font-size to 62.5% for Easier em Conversion

    如果你想擁有更加靈活的布局,你應(yīng)該使用em而不是pixel或者points。通過設(shè)置你的字體62.5%,你可以很容易的通過設(shè)置em為pixel的1/10來設(shè)置文字。

     
     
     
    1. body {
    2.   font-size: 62.5%; /* font-size 1em = 10px */
    3. }
    4. p {
    5.   font-size: 1.2em; /* 1.2em = 12px */
    6. }

    11. Vertically Align Text

    如果你設(shè)置line-height和父元素高度相同,則很容易讓文字垂直居中

     
     
     
    1. div { width:100px; height:100px; }
    2. div p { line-height:100px; }

    12. How to Create 3D Text With CSS3

    使用text-shadow屬性,你可以只使用CSS3創(chuàng)建3D文字

     
     
     
    1. p.threeD
    2. {
    3.     text-shadow:
    4.         -1px 1px 0 #ddd,
    5.         -2px 2px 0 #c8c8c8,
    6.         -3px 3px 0 #ccc,
    7.         -4px 4px 0 #b8b8b8,
    8.         -4px 4px 0 #bbb,
    9.         0px 1px 1px rgba(0,0,0,.4),
    10.         0px 2px 2px rgba(0,0,0,.3),
    11.         -1px 3px 3px rgba(0,0,0,.2),
    12.         -1px 5px 5px rgba(0,0,0,.1),
    13.         -2px 8px 8px rgba(0,0,0,.1),
    14.         -2px 13px 13px rgba(0,0,0,.1)
    15.         ;
    16. }

    13. Wrapping Long URLs and Text Content with CSS

    這段代碼將會(huì)幫助你使得一行文字不至于太長,會(huì)自動(dòng)根據(jù)內(nèi)容寬度來折行

     
     
     
    1. pre {
    2.     white-space: pre;           /* CSS 2.0 */
    3.     white-space: pre-wrap;      /* CSS 2.1 */
    4.     white-space: pre-line;      /* CSS 3.0 */
    5.     white-space: -pre-wrap;     /* Opera 4-6 */
    6.     white-space: -o-pre-wrap;   /* Opera 7 */
    7.     white-space: -moz-pre-wrap; /* Mozilla */
    8.     white-space: -hp-pre-wrap;  /* HP Printers */
    9.     word-wrap: break-word;      /* IE 5+ */
    10.     }

    14. Fancy Ampersand

    使得你的"&"符號(hào)更加漂亮

     
     
     
    1. .amp {
    2. font-family: Baskerville, 'Goudy Old Style', Palatino, 'Book Antiqua', serif;
    3. font-style: italic;
    4. font-weight: normal;
    5. }

    15. Pull Quotes for Improved Reading

    使得你的引用更加明顯,將引用浮動(dòng)到左邊或者右邊,并且包圍內(nèi)容

     
     
     
    1. .pullquote {
    2. width: 300px;
    3. float: right;
    4. margin: 5px;
    5. font-family: Georgia, "Times New Roman", Times, serif;
    6. font: italic bold #ff0000 ; }

    16. Rounded Borders Around Images

    使用CSS3可以很容易的生成圖片圓角

     
     
     
    1. img {
    2. -webkit-border-radius: 25px;
    3. -moz-border-radius: 25px;
    4. border-radius: 25px;
    5. }

    17. Image Preloader

    圖片加載中先加載一個(gè)小圖片,這樣提示用戶預(yù)加載圖片

     
     
     
    1. img
    2. {
    3.     background: url(img/preloader.gif) no-repeat 50% 50%;
    4. }

    #p#

    18. CSS3 Opacity

    使用opacity屬性,幫助你透明看到元素,你可以創(chuàng)建一個(gè)分層的紋理背景

     
     
     
    1. div.L1 { background:#036; opacity:0.2; height:20px; }
    2. div.L2 { background:#036; opacity:0.4; height:20px; }
    3. div.L3 { background:#036; opacity:0.6; height:20px; }
    4. div.L4 { background:#036; opacity:0.8; height:20px; }
    5. div.L5 { background:#036; opacity:1.0; height:20px; }

    19. Highlight links that open in a new window

    這段代碼允許你通過顯示不同的樣式清楚地分辨新窗口/標(biāo)簽頁打開的link。

     
     
     
    1. a[target="_blank"]:before,
    2. a[target="new"]:before {
    3. margin:0 5px 0 0;
    4. padding:1px;
    5. outline:1px solid #333;
    6. color:#333;
    7. background:#ff9;
    8. font:12px "Zapf Dingbats";
    9. content: "\279C";
    10. }

    20. The New Bulletproof @Font-Face Syntax

    跨瀏覽器的CSS代碼片斷,幫助你定義font face

     
     
     
    1. @font-face {
    2.     font-family: 'MyFontFamily';
    3.     src: url('myfont-webfont.eot?#iefix') format('embedded-opentype'),
    4.          url('myfont-webfont.woff') format('woff'),
    5.          url('myfont-webfont.ttf')  format('truetype'),
    6.          url('myfont-webfont.svg#svgFontName') format('svg');
    7.     }

    21. Flip an Image

    翻轉(zhuǎn)圖片的CSS代碼片斷。特別適合你翻轉(zhuǎn)圖標(biāo)

     
     
     
    1. img {
    2.         -moz-transform: scaleX(-1);
    3.         -o-transform: scaleX(-1);
    4.         -webkit-transform: scaleX(-1);
    5.         transform: scaleX(-1);
    6.         filter: FlipH;
    7.         -ms-filter: "FlipH";
    8. }

    22. Email Link With An Image

    快速的方法自動(dòng)添加一個(gè)電子郵件圖片到你的email鏈接

     
     
     
    1. a[href^="mailto:"] {
    2.      background: url(images/email.png) no-repeat right top;
    3.      padding-right:10px;
    4. }

    23. Beautiful Blockquotes

    美化你的引用

     
     
     
    1. blockquote {
    2.      background:#f9f9f9;
    3.      border-left:10px solid #ccc;
    4.      margin:1.5em 10px;
    5.      padding:.5em 10px;
    6.      quotes:"\201C""\201D""\2018""\2019";
    7. }
    8. blockquote:before {
    9.      color:#ccc;
    10.      content:open-quote;
    11.      font-size:4em;
    12.      line-height:.1em;
    13.      margin-right:.25em;
    14.      vertical-align:-.4em;
    15. }
    16. blockquote p {
    17.      display:inline;
    18. }

    24. Browser CSS hacks

    大量的CSS hack幫助你讓你的網(wǎng)站在所有瀏覽器下顯示一致

     
     
     
    1. /***** Selector Hacks ******/
    2. /* IE6 and below */
    3. * html #uno  { color: red }
    4. /* IE7 */
    5. *:first-child+html #dos { color: red } 
    6. /* IE7, FF, Saf, Opera  */
    7. html>body #tres { color: red }
    8. /* IE8, FF, Saf, Opera (Everything but IE 6,7) */
    9. html>/**/body #cuatro { color: red }
    10. /* Opera 9.27 and below, safari 2 */
    11. html:first-child #cinco { color: red }
    12. /* Safari 2-3 */
    13. html[xmlns*=""] body:last-child #seis { color: red }
    14. /* safari 3+, chrome 1+, opera9+, ff 3.5+ */
    15. body:nth-of-type(1) #siete { color: red }
    16. /* safari 3+, chrome 1+, opera9+, ff 3.5+ */
    17. body:first-of-type #ocho {  color: red }
    18. /* saf3+, chrome1+ */
    19. @media screen and (-webkit-min-device-pixel-ratio:0) {
    20.  #diez  { color: red  }
    21. }
    22. /* iPhone / mobile webkit */
    23. @media screen and (max-device-width: 480px) {
    24.  #veintiseis { color: red  }
    25. }
    26. /* Safari 2 - 3.1 */
    27. html[xmlns*=""]:root #trece  { color: red  }
    28. /* Safari 2 - 3.1, Opera 9.25 */
    29. *|html[xmlns*=""] #catorce { color: red  }
    30. /* Everything but IE6-8 */
    31. :root *> #quince { color: red  }
    32. /* IE7 */
    33. *+html #dieciocho {  color: red }
    34. /* Firefox only. 1+ */
    35. #veinticuatro,  x:-moz-any-link  { color: red }
    36. /* Firefox 3.0+ */
    37. #veinticinco,  x:-moz-any-link, x:default  { color: red  }
    38. /* FF 3.5+ */
    39. body:not(:-moz-handler-blocked) #cuarenta { color: red; }
    40. /***** Attribute Hacks ******/
    41. /* IE6 */
    42. #once { _color: blue }
    43. /* IE6, IE7 */
    44. #doce { *color: blue; /* or #color: blue */ }
    45. /* Everything but IE6 */
    46. #diecisiete { color/**/: blue }
    47. /* IE6, IE7, IE8 */
    48. #diecinueve { color: blue\9; }
    49. /* IE7, IE8 */
    50. #veinte { color/*\**/: blue\9; }
    51. /* IE6, IE7 -- acts as an !important */
    52. #veintesiete { color: blue !ie; } /* string after ! can be anything */
    53. /* IE8, IE9 */
    54. #anotherone  {color: blue\0/;} /* must go at the END of all rules */

    25. How To Change The Default Text Selection Color on your Blog

    修改高亮的文字顏色

     
     
     
    1. ::selection {
    2.    background: #ffb7b7; /* Safari */
    3.         color: #ffffff;
    4.    }
    5. ::-moz-selection {
    6.    background: #ffb7b7; /* Firefox */
    7.         color: #ffffff;
    8.    }

    26. Clearfix

     
     
     
    1. .clearfix:after {
    2.     visibility: hidden;
    3.     display: block;
    4.     font-size: 0;
    5.     content: " ";
    6.     clear: both;
    7.     height: 0;
    8. }
    9. .clearfix { display: inline-block; }
    10. /* start commented backslash hack \*/
    11. * html .clearfix { height: 1%; }
    12. .clearfix { display: block; }
    13. /* close commented backslash hack */

    27. Hide Logo Text With Text Indent

    使得你的logo SEO友好。保證logo文字不顯示

     
     
     
    1. h1 {
    2.         text-indent:-9999px;
    3.         margin:0 auto;
    4.         width:400px;
    5.         height:100px;   當(dāng)前名稱:30個(gè)你應(yīng)該知道的實(shí)用CSS代碼片斷
      網(wǎng)頁URL:http://www.5511xx.com/article/dhpsjgs.html