`

10个有用的CSS

阅读更多

The top 10 most useful css snippets of today.

I have noticed myself to use a few different code snippets on a daily basis so I thought some of you might find them useful. So here we go.

     
  1.    
    center     
    Centering a website (or other elements)
       
    The HTML
    1. <DIV class=wrap>  
    2. </DIV>  
    3.   
    4. <!-- end wrap -->  
    <!-- end wrap -->

    The CSS

     

    1. .wrap { width:960pxmargin:0 auto;}  
      .wrap { width:960px; margin:0 auto;}
    

     

    This is an oldie, but apperantly it is not as obvious as you would think.

     

     


  2.    
    stickyfooter

       
    Sticky Footer (make footer always be on bottom without absolute positioning)

     
    The HTML

     

    1. <DIV id=wrap>  
    2. <DIV class=clearfix id=main>  
    3. </DIV>  
    4. </DIV>  
    5. <DIV id=footer>  
    6. </DIV>  

    The CSS

     

    1.   * { margin:0; padding:0; }   
    2. html, body, #wrap { height: 100%; }   
    3. body > #wrap {heightautomin-height: 100%;}   
    4. #main { padding-bottom150px; }  /* must be same height as the footer */  
    5. #footer {   
    6. positionrelative;   
    7. margin-top: -150px/* negative value of footer height */  
    8. height150px;   
    9. clear:both;}   
    10. /* CLEAR FIX*/  
    11. .clearfix:after {content".";   
    12. displayblock;   
    13. height: 0;   
    14. clearboth;   
    15. visibilityhidden;}   
    16. .clearfix {displayinline-block;}   
    17. /* Hides from IE-mac */  
    18. * html .clearfix { height: 1%;}   
    19. .clearfix {displayblock;}   
    20. /* End hide from IE-mac */  
      * { margin:0; padding:0; }
    html, body, #wrap { height: 100%; }
    body > #wrap {height: auto; min-height: 100%;}
    #main { padding-bottom: 150px; }  /* must be same height as the footer */
    #footer {
    position: relative;
    margin-top: -150px; /* negative value of footer height */
    height: 150px;
    clear:both;}
    /* CLEAR FIX*/
    .clearfix:after {content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;}
    .clearfix {display: inline-block;}
    /* Hides from IE-mac */
    * html .clearfix { height: 1%;}
    .clearfix {display: block;}
    /* End hide from IE-mac */
    

     

    As of recently i have had to use this over 50 times… i think this is one of the most important tricks you will learn today.

     

     


  3.    
    min-height

       
    Cross-Browser Min Height

     
    The CSS

     

    1. .element { min-height:600pxheight:auto !importantheight:600px; }  
      .element { min-height:600px; height:auto !important; height:600px; }
    

     

    You can replace the min-height and heigth with 12em or another value that works for you.

     

     


  4.    
    box-shadow

       
    Box Shadow (CSS3)

     
    The CSS

     

    1. .box { box-shadow: 5px 5px 5px #666;  -moz-box-shadow: 5px 5px 5px #666;  -webkit-box-shadow: 5px 5px 5px #666; }  
      .box { box-shadow: 5px 5px 5px #666;  -moz-box-shadow: 5px 5px 5px #666;  -webkit-box-shadow: 5px 5px 5px #666; }
    

     

    As you can see since this is a CSS3 property you will need all the three commands to make it cross browser(except for ie of course). The first 2 measurements are for horizontal offset and the vertical offset. The third number is for the blur radius. And the last is the color of the shadow.

     

     


  5.    
    text-shadow

       
    Text Shadow (CSS3) with IE hack

     
    The CSS

     

    1. .text { text-shadow1px 1px 1px #666; filter: Shadow(Color=#666666, Direction=135, Strength=5); }  
      .text { text-shadow: 1px 1px 1px #666; filter: Shadow(Color=#666666, Direction=135, Strength=5); }
    

     

    This technique is great for all modern browsers, the IE fix works but it is not amazing quality.

     

     


  6.    
    opac

       
    Cross Browser CSS Opacity

     
    The CSS

     

    1.   .transparent {   
    2. /* Modern Browsers */ opacity: 0.7;   
    3. /* IE 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";   
    4. /* IE 5-7 */ filter: alpha(opacity=70);   
    5. /* Netscape */ -moz-opacity: 0.7;   
    6. /* Safari 1 */ -khtml-opacity: 0.7;   
    7. }  
      .transparent {
    /* Modern Browsers */ opacity: 0.7;
    /* IE 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
    /* IE 5-7 */ filter: alpha(opacity=70);
    /* Netscape */ -moz-opacity: 0.7;
    /* Safari 1 */ -khtml-opacity: 0.7;
    }
    

     

    Opacity can be used for plenty of elements, it adds a certain new age style we all strive for. Notice that in some browsers transperancy is inherited by all child elements!

     

     


  7.    
    reset

       
    The Famous Meyer Reset

     
    The CSS

     

    1.   html, body, div, span, applet, object, iframe,   
    2. h1, h2, h3, h4, h5, h6, p, blockquote, pre,   
    3. a, abbr, acronym, address, big, cite, code,   
    4. del, dfn, em, font, img, ins, kbd, q, s, samp,   
    5. small, strike, strong, sub, sup, tt, var,   
    6. dl, dt, dd, ol, ul, li,   
    7. fieldset, form, label, legend,   
    8. table, caption, tbody, tfoot, thead, tr, th, td {   
    9. margin: 0;   
    10. padding: 0;   
    11. border: 0;   
    12. outline: 0;   
    13. font-weight: inherit;   
    14. font-style: inherit;   
    15. font-size: 100%;   
    16. font-family: inherit;   
    17. vertical-alignbaselinebaseline;   
    18. }   
    19. /* remember to define focus styles! */  
    20. :focus {   
    21. outline: 0;   
    22. }   
    23. body {   
    24. line-height: 1;   
    25. colorblack;   
    26. backgroundwhite;   
    27. }   
    28. ol, ul {   
    29. list-stylenone;   
    30. }   
    31. /* tables still need 'cellspacing="0"' in the markup */  
    32. table {   
    33. border-collapseseparate;   
    34. border-spacing: 0;   
    35. }   
    36. caption, th, td {   
    37. text-alignleft;   
    38. font-weightnormal;   
    39. }   
    40. blockquote:before, blockquote:after,   
    41. q:before, q:after {   
    42. content"";   
    43. }   
    44. blockquote, q {   
    45. quotes"" "";   
    46. }  
      html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, font, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-weight: inherit;
    font-style: inherit;
    font-size: 100%;
    font-family: inherit;
    vertical-align: baseline;
    }
    /* remember to define focus styles! */
    :focus {
    outline: 0;
    }
    body {
    line-height: 1;
    color: black;
    background: white;
    }
    ol, ul {
    list-style: none;
    }
    /* tables still need 'cellspacing="0"' in the markup */
    table {
    border-collapse: separate;
    border-spacing: 0;
    }
    caption, th, td {
    text-align: left;
    font-weight: normal;
    }
    blockquote:before, blockquote:after,
    q:before, q:after {
    content: "";
    }
    blockquote, q {
    quotes: "" "";
    }
    

     

    This is the most useful css reset out there, i use it for almost everything I work on (even the 52framework, coming soon).

     

     


  8.    
    dotted

       
    Removing the dotted outlines

     
    The CSS

     

    1. a, a:active { outlinenone; }  
      a, a:active { outline: none; }
    

     

    I find myself getting very annoyed with the dotted outline (especially for text-indented elements that are off the page).

     

     


  9.    
    rounded

       
    Rounded Corners (non ie)

     
    The CSS

     

    1.   .element {   
    2. -moz-border-radius: 5px;   
    3. -webkit-border-radius: 5px;   
    4. border-radius: 5px/* future proofing */  
    5. }   
    6. .element-top-left-corner {   
    7. -moz-border-radius-topleft: 5px;   
    8. -webkit-border-top-left-radius: 5px;   
    9. }  
      .element {
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px; /* future proofing */
    }
    .element-top-left-corner {
    -moz-border-radius-topleft: 5px;
    -webkit-border-top-left-radius: 5px;
    }
    

     

    Love rounded corners? Don’t want to slave over images and elements to get the effect? This is your solution, and elements still look fine in ie.

     

     


  10.    
    import

       
    Override Inline Styles

     
    The CSS

     

    1.   .override {   
    2. font-size14px !important;   
    3. }  
      .override {
    font-size: 14px !important;
    }
    

     

分享到:
评论

相关推荐

    10 个有用免费 CSS3 强大工具

    10 个有用免费 CSS3 强大工具

    10个非常有用的CSS hack和技术

    10个非常有用的CSS hack,浏览器兼容性处理

    10个Web前端开发中免费且非常有用CSS代码.docx

    10个Web前端开发中免费且非常有用CSS代码.docx

    10个Web前端开发中免费且非常有用CSS代码共2页.pd

    10个Web前端开发中免费且非常有用CSS代码共2页.pdf.zip

    十天学会DIV CSS教程完整版完美整理 完整代码.pdf

    完整的DIV+CSS教程,网站设计是做软件的入门,也是最简单,而且最为实用的设计需求。这么多年软件做下来,其实基本上软件设计的原理都有那么一些继承和发展。这篇文章对于初学网站前端设计的朋友很有用。学了这个,...

    10个你未必知道的CSS技巧

    10个你未必知道的CSS技巧 很有用

    《CSS全程指南》随书光盘

    本书将最有用的CSS技术汇总在一起,在介绍基本的CSS概念和最佳实践之后,讨论了核心的CSS技术,例如图像、链接、列表操纵、表单设计等。每一章内容由浅入深,直到建立比较复杂的示例。之后本书又着重讨论如何使用DIV...

    十天学会DIV+CSS教程完整版_完美整理+完整代码

    网站设计是做软件的入门,也是最简单,而且最为实用的设计需求。这么多年软件做下来,其实基本上...这篇文章对于初学网站前端设计的朋友很有用。学了这个,后面再去学习js,再学php。开发常见的企业级web应用就足够了

    推荐14款非常有用的 CSS 网格系统生成工具

    一个系统化、结构合理的布局使得能够更快更轻松的组织网站的内容。网格系统为网页设计师们提供了一种快速构造网页内容布局的方法,帮助设计师们节省了大量的时间和精力。 1. Tiny Fluid Grid 2. ZURB CSS Grid ...

    div+css技术收集

    javascript+css一张背景图片的不同切换,DIV背景图片变暗,CSS渐变色,设置div的透明背景,10个非常有用的CSS技巧,图片凸起效果,点击div背景图切换,动态背景

    10款CSS+JS结合的实用代码

    很实用的一些代码.对于做网站很有用的 Css+Xhtml代码,关键字:web2.0 隐藏内容代码 css实用代码.

    10个很棒的 CSS3 开发工具 推荐

    CSS3 是对 CSS 规范的一个很大的改善和增强,它使得 Web 开发人员可以很容易的在网站中加入时尚的效果。尽管如此,有几个工具可以在你使用 CSS3 制作网站的时候起...在这篇文章中,收集了10款非常有用的工具推荐给大家

    10个必备的CSS技巧总结

    今天我们精心准备了10条对网页设计师最有用的CSS技巧,如果你想设计出独一无二脱颖而出的网页你必须得好好注意了。这篇博客是在与一家提供高质量印刷服务的在线印刷公司“ Business Card Printing”合作时写的。 1. ...

    必须掌握10个非常不错的CSS技巧

    在这里,巧妙的运用CSS的技巧,可以让你不用修改HTML就能得到很好的博客或者模板外观。我收集了一些非常有用的CSS技巧让我们设计博客时更炫更酷。...这里我收集了10个很不错的CSS技巧,你可以用在你的

    要知道的10个CSS技巧

    今天我们精心准备了10条对网页设计师最有用的CSS技巧,如果你想设计出独一无二脱颖而出的网页你必须得好好注意了。 1. @font-face 一种用其他服务器上的字体的好方法。很明显,如果你不能在托管服务器上找到你需要...

    技术讲座_Div+Css布局

    div css表单布局的五个小技巧可以帮助你更灵活的控制表单,使页面更加满意。  1、表单文本输入的移动选择:  在文本输入栏中,如果加入了提示,来访者往往要用鼠标选取后删除,再输入有用的信息。其实只要加入...

    10个非常实用的CSS hack技术

    但是一些很有用的技术对很多开发人员来说仍然比较隐秘,所以本文中,让我们看看10个肯定能提高你设计的CSS技术吧 1 – 跨浏览器的inline-block CSS Code复制内容到剪贴板 &lt;style&gt; li { width: 200px; ...

    reduce-css-calc:最大程度地减少CSS calc()函数

    对于或类的软件包尤其有用。 安装 npm install reduce-css-calc 用法 var reducedString = reduceCSSCalc(string, precision) var reduceCSSCalc = require ( 'reduce-css-calc' ) reduceCSSCalc ( "calc(1 + 1)...

    AnimateMe:AnimateMe 是流行的 animate.css 项目的修改版本。 我保留了有用的部分并修改了一些动画以使其更实用(来自我的 POV)

    我保留了有用的部分并修改了一些动画以使其更实用(来自我的 POV) ##基本用法 在文档的&lt;head&gt;包含样式表 &lt; head &gt; &lt; link rel =" stylesheet " href =" animateme.min.css " &gt; &lt;/ head &gt...

Global site tag (gtag.js) - Google Analytics