分享

每位设计师都应该拥有的50个CSS代码片段(2)

 java_laq小馆 2013-07-02

每位设计师都应该拥有的50个CSS代码片段(2)

2013-06-07 10:39 OSCHINA编译 我要评论(0) 字号:T | T
一键收藏,随时查看,分享好友!

面对每年如此多的新趋势 ,保持行业的领先是个很困难问题. 网站设计者和前端工程师都已经全面的使用 CSS3 properties, 决定这些的是 浏览器支持 和新的特性. 但是还是有些优秀的CSS2代码片段和CSS3一起运行中.

AD: 2013大数据全球技术峰会课程PPT下载

7.一般媒体查询

  1. /* Smartphones (portrait and landscape) ----------- */ 
  2. @media only screen   
  3. and (min-device-width : 320px) and (max-device-width : 480px) {  
  4.   /* Styles */ 
  5. }  
  6.  
  7. /* Smartphones (landscape) ----------- */ 
  8. @media only screen and (min-width : 321px) {  
  9.   /* Styles */ 
  10. }  
  11.  
  12. /* Smartphones (portrait) ----------- */ 
  13. @media only screen and (max-width : 320px) {  
  14.   /* Styles */ 
  15. }  
  16.  
  17. /* iPads (portrait and landscape) ----------- */ 
  18. @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {  
  19.   /* Styles */ 
  20. }  
  21.  
  22. /* iPads (landscape) ----------- */ 
  23. @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {  
  24.   /* Styles */ 
  25. }  
  26.  
  27. /* iPads (portrait) ----------- */ 
  28. @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {  
  29.   /* Styles */ 
  30. }  
  31.  
  32. /* Desktops and laptops ----------- */ 
  33. @media only screen and (min-width : 1224px) {  
  34.   /* Styles */ 
  35. }  
  36.  
  37. /* Large screens ----------- */ 
  38. @media only screen and (min-width : 1824px) {  
  39.   /* Styles */ 
  40. }  
  41.  
  42. /* iPhone 4 ----------- */ 
  43. @media only screen and (-webkit-min-device-pixel-ratio:1.5), only screen and (min-device-pixel-ratio:1.5) {  
  44.   /* Styles */ 

Code Source

这是一个很棒的模版,你能在CSS-Tricks找到其它零碎的媒体查询。不管怎样我已经把他们的例子全拷下来了,那里面包括了成吨的实际的移动设备。这些代码甚至能针对视网膜屏设备,使用最小设备像素比例。

8. 现代字体栈

  1. /* Times New Roman-based serif */ 
  2. font-family: Cambria, "Hoefler Text", Utopia, "Liberation Serif""Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;  
  3.  
  4. /* A modern Georgia-based serif */ 
  5. font-family: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif""Liberation Serif", Georgia, serif;  
  6.  
  7. /*A more traditional Garamond-based serif */ 
  8. font-family"Palatino Linotype", Palatino, Palladio, "URW Palladio L""Book Antiqua", Baskerville, "Bookman Old Style""Bitstream Charter""Nimbus Roman No9 L", Garamond, "Apple Garamond""ITC Garamond Narrow""New Century Schoolbook""Century Schoolbook""Century Schoolbook L", Georgia, serif;  
  9.  
  10. /*The Helvetica/Arial-based sans serif */ 
  11. font-family: Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans""Gill Sans MT""Myriad Pro", Myriad, "DejaVu Sans Condensed""Liberation Sans""Nimbus Sans L"Tahoma, Geneva, "Helvetica Neue"HelveticaArialsans-serif;  
  12.  
  13. /*The Verdana-based sans serif */ 
  14. font-family: Corbel, "Lucida Grande""Lucida Sans Unicode""Lucida Sans""DejaVu Sans""Bitstream Vera Sans""Liberation Sans"Verdana"Verdana Ref"sans-serif;  
  15.  
  16. /*The Trebuchet-based sans serif */ 
  17. font-family"Segoe UI", Candara, "Bitstream Vera Sans""DejaVu Sans""Bitstream Vera Sans""Trebuchet MS"Verdana"Verdana Ref"sans-serif;  
  18.  
  19. /*The heavier "Impact" sans serif */ 
  20. font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat""Bitstream Vera Sans Bold""Arial Black"sans-serif;  
  21.  
  22. /*The monospace */ 
  23. font-family: Consolas, "Andale Mono WT""Andale Mono""Lucida Console""Lucida Sans Typewriter""DejaVu Sans Mono""Bitstream Vera Sans Mono""Liberation Mono""Nimbus Mono L", Monaco, "Courier New", Courier, monospace;  

Code Source

你很难为设计一个新的页面头脑风暴式的想出自己的CSS字体栈。我希望这一小片代码能减轻一些折磨,并给你一些可以着手开始的模版。如果你想找更多的例子,查看一下CSS 字体栈 ,这是我最喜欢的资源之一。

9. 自定义文本选择

  1. ::selection { background#e2eae2; }  
  2. ::-moz-selection { background#e2eae2; }  
  3. ::-webkit-selection { background#e2eae2; } 

一些新式的浏览器会允许你定义页面中的高亮颜色。默认这是设为淡蓝色的,但你可以设置任何投你所好的颜色值,这小片代码包括了典型的::selection目标以及专为Webkit和Mozilla的特定前缀。

10.隐藏H1文本为Logo标志

  1. h1 {  
  2.     text-indent-9999px;  
  3.     margin0 auto;  
  4.     width320px;  
  5.     height85px;  
  6.     backgroundtransparent url("images/logo.png"no-repeat scroll;  

我第一次注意到这个技术实现是在古老的Digg 布局 。为了SEO的目的,你也可以设置一个包含有你的站点名称的H1标签。但使用CSS我们能移走这个文本使它不可见,并用一个客制化的logo图片替换它。

11. polaroid图像边界

  1. img.polaroid {  
  2.     background:#000/*Change this to a background image or remove*/ 
  3.     border:solid #fff;  
  4.     border-width:6px 6px 20px 6px;  
  5.     box-shadow:1px 1px 5px #333/* Standard blur at 5px. Increase for more depth */ 
  6.     -webkit-box-shadow:1px 1px 5px #333;  
  7.     -moz-box-shadow:1px 1px 5px #333;  
  8.     height:200px/*Set to height of your image or desired div*/ 
  9.     width:200px/*Set to width of your image or desired div*/ 

Code Source

应用这个基础的片段将使你能在你的图像上实现.polaroid 类。这将会创建老照片风格效果,带一个很宽的白边和一些淡淡的阴影。你要更新宽/高数值,以便和你的图片尺寸和网站布局相匹配。

12. 锚链接伪类

  1. a:link { colorblue; }  
  2. a:visited { colorpurple; }  
  3. a:hover { colorred; }  
  4. a:active { color: yellow; } 

Code Source

大多数CSS开发者知道锚链接类和:hover效果。但是我想引入这小段代码给新手做个参考。这些是一个锚链接和一些其他HTML元素的四个默认状态。把它们留在手边,直到你可以记住一些更复杂的情况。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多