Archive for 一月, 2010

一月 24th, 2010

CSS Reset(复位)

No Comments, 随笔记录, by admin.

Css Reset是什么? 有些同行叫 “css复位”,有些可能叫 “默认css”…..
相信看完全文您会对Css Reset有个重新的认识
PS:

* {   
 padding: 0;   
 margin: 0;   
 } 

这就是最常用的Css Reset,但是这里会有很多问题。
原文前部分说了很多关于Css,以及各浏览器的css规则的不同,而制定”Css Reset”也是为了兼容与统一,正确有效的使用”Css Reset”可以在某种程度上节约时间与金钱.
非常感谢Perishable的整理与归纳
下面是关于几类Css Reset的简单介绍,本人能力有限.只能理解大概意思,还请各位看官见谅.
Minimalistic Reset [ Version 1 ]
相信这一段你经常看到.而且也是我们经常用到的

* {   
 padding: 0;   
 margin: 0;   
 }  

Minimalistic Reset [ Version 2 ]
border:0的设计有些不靠谱了

* {   
 padding: 0;   
 margin: 0;   
 border: 0;   
 }

Minimalistic Reset [ Version 3 ]
当然这个也是不推荐的.会跟某些默认样式有冲突

* {   
 outline: 0;   
 padding: 0;   
 margin: 0;   
 border: 0;   
 }   

Condensed Universal Reset
这是作者当前比较钟意的一种写法.保证了相对普遍浏览器样式的统一性.

* {   
 vertical-align: baselinebaseline;   
 font-weight: inherit;   
 font-family: inherit;   
 font-style: inherit;   
 font-size: 100%;   
 border: 0 none;   
 outline: 0;   
 padding: 0;   
 margin: 0;   
 }  

Poor Man’s Reset
其实这也是我们常用的一类Css [...]

1. 将网页或元素居中       
     

    
HTML:
<div class=”wrap”>  
</div><!– end wrap –>  
CSS:
 
.wrap { width:960px; margin:0 auto;}  
 
2.Sticky Footer (让页脚永远停靠在页面底部,而不是根据绝对位置)
   

   

 
HTML:
<div id=”wrap”>  
  
<div id=”main” class=”clearfix”>  
  
</div>  
  
</div>  
  
<div id=”footer”>  
  
</div>  
CSS:
* { 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 */  
 
3.跨浏览器最小高度设置      

       
 CSS:
.element { min-height:600px; height:auto !important; height:600px; }  
 
4.Box阴影(CSS3)
   

   

    
CSS:
.box { box-shadow: 5px 5px 5px #666;  -moz-box-shadow: 5px 5px 5px #666;  -webkit-box-shadow: 5px 5px 5px #666; }  
 
5.文字阴影(CSS3)
   

        
CSS:
.text { text-shadow: 1px 1px 1px #666; filter: Shadow(Color=#666666, Direction=135, Strength=5); }  
 
6.跨浏览器的CSS透明度
   

CSS:
.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;  
    
}  
 
7.著名的 Meyer Reset(重置)
   

CSS:
  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: ”” ””;  
}  
   
 
8.删除虚线轮廓      

   

CSS:
a, a:active { outline: none; }  
 
9.圆角
   

         
CSS:
.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;  
}  
 
10.覆盖内联的样式

     
 CSS:
.override {  
 font-size: 14px !important;  
}  
点击查看原文:http://webdevmania.com/archive/top_10_css_snippets/

IE6,IE7,IE8,Firefox兼容的css hack
补充:
.color{
 background-color: #CC00FF;  /*所有浏览器都会显示为紫色*/
 background-color: #FF0000\9; /*IE6、IE7、IE8会显示红色*/
 *background-color: #0066FF;  /*IE6、IE7会变为蓝色*/  
 _background-color: #009933;  /*IE6会变为绿色*/
}
好多css hack,最重要的是简单实用能解决问题就行了
总结:
\9: IE6 IE7 IE8
*: IE6 IE7
_: IE6
*+: IE7
—————————————-
IE6,IE7,Firefox兼容的css hack
第一种办法:
body
{
    background:red;
    *background:blue !important;  
    *background: green;
}
第一排给Firefox以及其他浏览器看;
第二排给IE7,IE7既能能识别*号,也能识别important;
第三排给IE6也能识别*号;
第二种办法,使用_来区分IE6:
body
{
    background:red;
    *background:blue;  
    _background: green;
}
第一排给Firefox以及其他浏览器看;
第二排给IE7,IE7既能能识别*号;
第三排给IE6能识别下划线;
CSS对浏览器器的兼容性具有很高的价值,通常情况下IE和Firefox存在很大的解析差异,这里介绍一下兼容要点。
常见兼容问题:
  1.DOCTYPE 影响 CSS 处理(但这个声明对于WEB标准的验证是非常重要的)
  2.FF: div 设置 margin-left, margin-right 为 auto 时已经居中, IE 不行
  3.FF: body 设置 text-align 时, div 需要设置 margin: auto(主要是 margin-left,margin-right) 方可居中
  4.FF: 设置 padding 后, div 会增加 [...]

一月 24th, 2010

CSS3-text-shadow

No Comments, 随笔记录, by admin.

一. text-shadow介绍
属性值: none | [, ] *
初始值: none
适用于: 所有元素以及生成的内容
可继承: 否
百分比: 不支持
媒介: 视觉
二. 对shadow的说明
a. shadow的形式有两种:
(1) []
(2) []
b. 和是可选的, 当未指定时, 将使用文本颜色; 当未指定时, 半径值为0;
c. shadow可以是逗号分隔的列表, 如:
text-shadow: 2px 2px 2px #ccc, 3px 3px 3px #ddd;
d. 阴影效果会按照shadow list中指定的顺序应用到元素上;
e. 这些阴影效果有可能相互重叠, 但不会叠加文本本身;
f. 阴影可能会跑到容器的边界之外, 但不会影响容器的大小.
三. 测试实例
xhtml:
I have shadow effect!!!
I have shadow effect!!!
css:
.para1 {
text-shadow: 2px 2px 2px #333;
}
.para2 {
[...]

CSS与JS紧密配合,为我们的页面增添了很多别致的效果。为了达到某种特殊的效果我们需要用Javascript动态的去更改某一个标签的CSS属性。
比如:鼠标经过一个图片时我们让图片加一个边框,代码可能是这样:JavaScript中style后面的属性应该是什么?
<script type=”text/javascript”>
function imageOver(e) {
e.style.border=”1px solid red”;
}
function imageOut(e) {
e.style.borderWidth=0;
}
</script>
<img src=”http://www.knowsky.com/css.png” onmouseover=”imageOver(this)” onmouseout=”imageOut(this)” />
JavaScript CSS Style属性对照表
盒子标签和属性对照
CSS语法 (不区分大小写)   JavaScript语法 (区分大小写)
border   border
border-bottom   borderBottom
border-bottom-color   borderBottomColor
border-bottom-style   borderBottomStyle
border-bottom-width   borderBottomWidth
border-color   borderColor
border-left   borderLeft
border-left-color   borderLeftColor
border-left-style   borderLeftStyle
border-left-width   borderLeftWidth
border-right   borderRight
border-right-color   borderRightColor
border-right-style   borderRightStyle
border-right-width   borderRightWidth
border-style   borderStyle
border-top   borderTop
border-top-color   borderTopColor
border-top-style   borderTopStyle
border-top-width   borderTopWidth
border-width   borderWidth
clear   clear
float   floatStyle
margin   margin
margin-bottom   marginBottom
margin-left   marginLeft
margin-right   marginRight
margin-top   marginTop
padding   padding
padding-bottom   paddingBottom
padding-left   paddingLeft
padding-right [...]