分享

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

 java_laq小馆 2013-07-02

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

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

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

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

13. 花式CSS3 Pull-引文

  1. .has-pullquote:before {  
  2.     /* Reset metrics. */ 
  3.     padding0;  
  4.     bordernone;  
  5.       
  6.     /* Content */ 
  7.     contentattr(data-pullquote);  
  8.       
  9.     /* Pull out to the right, modular scale based margins. */ 
  10.     floatright;  
  11.     width320px;  
  12.     margin12px -140px 24px 36px;  
  13.       
  14.     /* Baseline correction */ 
  15.     positionrelative;  
  16.     top: 5px;  
  17.       
  18.     /* Typography (30px line-height equals 25% incremental leading) */ 
  19.     font-size23px;  
  20.     line-height30px;  
  21. }  
  22.  
  23. .pullquote-adelle:before {  
  24.     font-family"adelle-1""adelle-2";  
  25.     font-weight100;  
  26.     top: 10px !important;  
  27. }  
  28.  
  29. .pullquote-helvetica:before {  
  30.     font-family"Helvetica Neue"Arialsans-serif;  
  31.     font-weightbold;  
  32.     top: 7px !important;  
  33. }  
  34.  
  35. .pullquote-facit:before {  
  36.     font-family"facitweb-1""facitweb-2"HelveticaArialsans-serif;  
  37.     font-weightbold;  
  38.     top: 7px !important;  

Code Source

Pull-引文(Pull-quotes)与块引用(blockquotes)不同,它们出现在你的博客或者新闻文章的一边。这些引文经常从文章中引用文本,所以它们和块引用显示的稍许不一样。这些默认类具有一些基础的属性,带有3个可供选择的独特的字体类型。

14.全屏背景和CSS3

  1. html {   
  2.     backgroundurl('images/bg.jpg'no-repeat center center fixed;   
  3.     -webkit-background-size: cover;  
  4.     -moz-background-size: cover;  
  5.     -o-background-size: cover;  
  6.     background-size: cover;  

Code Source

我应该标注一下这个代码在不支持CSS3语法的老式浏览器中不会正确的工作。然而如果你是在寻找一个不需要关心遗留系统支持的快速的解决方案,这是你能找到的最好的代码段!给你网站背景增加很大的照片同时又能使它们能在你滚动的时候保持可变尺寸和固定不动。

15. 垂直居中内容

  1. .container {  
  2.     min-height6.5em;  
  3.     displaytable-cell;  
  4.     vertical-alignmiddle;  

Code Source

使用 margin: 0 auto 技术,很容易就能使内嵌的内容位于你页面的水平正中。然而对垂直的文本要困难的多,尤其是考虑到滚动条和其它的方式。但这个是无需JavaScript就能完美无瑕工作的纯CSS解决方案。

16.强制垂直滚动条

  1. html { height101% } 

如果你的页面内容不能填满你的浏览器窗口整个高度,那么你不会焦灼于获取滚动条。但是改变大小将会强制它们出现,并给你的窗口宽度增加额外的10-15像素,推走你的页面内容。这个代码段将保证你的HTML元素总是比浏览器高一点点,强制滚动条一直停留在适当位置。

17. CSS3梯度模板

  1. #colorbox {  
  2.     background#629721;  
  3.     background-image: -webkit-gradient(linear, left topleft bottom, from(#83b842), to(#629721));  
  4.     background-image: -webkit-linear-gradient(top#83b842#629721);  
  5.     background-image: -moz-linear-gradient(top#83b842#629721);  
  6.     background-image: -ms-linear-gradient(top#83b842#629721);  
  7.     background-image: -o-linear-gradient(top#83b842#629721);  
  8.     background-image: linear-gradient(top#83b842#629721);  

CSS3梯度是新技术参数的另一个奇妙的部分。许多特定前缀难以记忆,所以这个代码片段将能为你每个项目节省一点时间。

18. @font-face模版

  1. @font-face {  
  2.     font-family'MyWebFont';  
  3.     srcurl('webfont.eot'); /* IE9 Compat Modes */ 
  4.     srcurl('webfont.eot?#iefix'format('embedded-opentype'), /* IE6-IE8 */ 
  5.     url('webfont.woff'format('woff'), /* Modern Browsers */ 
  6.     url('webfont.ttf')  format('truetype'), /* Safari, Android, iOS */ 
  7.     url('webfont.svg#svgFontName'format('svg'); /* Legacy iOS */ 
  8. }  
  9.       
  10. body {  
  11.     font-family'MyWebFont'Arialsans-serif;  

Code Source

这是另一些不是很容易记的CSS3代码。使用@font-face你可以给你的网站嵌入自己的TTF/OTF/SVG/WOFF文件,生成自定义的字体类型。为你未来的项目,将这个模版作为一个基本的例子。

19. 完整定义CSS3元素

  1. p {  
  2.     position:relative;  
  3.     z-index:1;  
  4.     padding10px;  
  5.     margin10px;  
  6.     font-size21px;  
  7.     line-height1.3em;  
  8.     color#fff;  
  9.     background#ff0030;  
  10.     -webkit-box-shadow: 0 0 0 4px #ff00302px 1px 4px 4px rgba(10,10,0,.5);  
  11.     -moz-box-shadow: 0 0 0 4px #ff00302px 1px 4px 4px rgba(10,10,0,.5);  
  12.     box-shadow: 0 0 0 4px #ff00302px 1px 6px 4px rgba(10,10,0,.5);  
  13.     -webkit-border-radius: 3px;  
  14.     -moz-border-radius: 3px;  
  15.     border-radius: 3px;  
  16. }  
  17.  
  18. p:before {  
  19.     content"";  
  20.     positionabsolute;  
  21.     z-index-1;  
  22.     top: 3px;  
  23.     bottom: 3px;  
  24.     left :3px;  
  25.     right: 3px;  
  26.     border2px dashed #fff;  
  27. }  
  28.  
  29. p a {  
  30.     color#fff;  
  31.     text-decoration:none;  
  32. }  
  33.  
  34. p a:hover, p a:focus, p a:active {  
  35.     text-decoration:underline;  

Code Source

20. CSS3 斑马条纹

  1. tbody tr:nth-child(odd) {  
  2.     background-color#ccc;  

Code Source

这个项目最好的应用是在数据列表上. 为40或50行的表来定义是很费劲的事情. 通过添加上面的CSS3条纹属性可以方便的为奇数行添上背景色.

21. 字符美化

  1. .amp {  
  2.     font-family: Baskerville, 'Goudy Old Style', Palatino, 'Book Antiqua', serif;  
  3.     font-styleitalic;  
  4.     font-weightnormal;  

Code Source

这个css类用在页面内容中围绕文字的span元素. 它会将一些典型的serif 字体用斜体形式显示.测试下看看是不是你喜欢的风格吧.

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

    0条评论

    发表

    请遵守用户 评论公约