码迷,mamicode.com
首页 > Web开发 > 详细

常用CSS代码片段

时间:2015-03-11 19:14:17      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

1、标准html页面模板

<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>标题</title>
    <!-- 引入css -->
    <link href="xxx.css" rel="stylesheet">
    <!-- 引入 JavaScript -->
    <script src="xxx.js"></script>
  </head>
  <body>
    <h1>你好,世界!</h1>
  </body>
</html>

 

2、CSS 重置

为了增强跨浏览器表现的一致性,我们使用了 Normalize.css,这是由 Nicolas Gallagher 和 Jonathan Neal 维护的一个CSS 重置样式库。

/* ======  reset ! normalize.css v3.0.1 | MIT License | git.io/normalize ====== */
*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box; box-sizing:border-box;}*:before,*:after {-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;}
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{background-color:#fff;margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:0.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0;-ms-interpolation-mode:bicubic;}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}

 

3、CSS Clearfix

.clearfix:before,.clearfix:after { content:"."; display:block; height:0; visibility:hidden;}
.clearfix:after {clear:both;}
.clearfix {*zoom:1;}

 

4、媒体对象

css代码

/* 清除浮动 */
.media:before,.media:after { content:"."; display:block; height:0; visibility:hidden;}
.media:after {clear:both;}
.media {*zoom:1;}

.media-bd {overflow:hidden;#zoom:1;}
.media-hd { margin:0 0 10px;}
.media .float-left { display:block; margin-right:20px;}
.media .float-left img {display:block;}
.media .float-right { margin-right:0; margin-left:20px;}

html代码(支持嵌套,.float-left自适应)

<div class="media">
     <a href="#" class="float-left"><img src="https://0.s3.envato.com/files/98745353/sixbros-80-80.png" /></a>
     <div class="media-bd">
          <h4 class="media-hd">论语学而篇第一</h4> 
          <p>《学而》是《论语》第一篇的篇名。《论语》中各篇一般都是以第一章的前二三个字作为该篇的篇名。《学而》一篇包括16章,内容涉及诸多方面。其中重点是「吾日三省吾身」;「节用而爱人,使民以时」;「礼之用,和为贵」以及仁、孝、信等道德范畴。</p>
     </div>
</div>

 

5、跨浏览器的透明度

.transparent {
    filter: alpha(opacity=50); /* internet explorer */
    -khtml-opacity: 0.5;      /* khtml, old safari */
    -moz-opacity: 0.5;       /* mozilla, netscape */
    opacity: 0.5;           /* fx, safari, opera */
}

 

常用CSS代码片段

标签:

原文地址:http://www.cnblogs.com/lingbiao/p/4330625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!