超实用CSS代码

1、鼠标悬浮替换图片

 <img src='../Images/img/menu01_dq.jpg'  οnmοuseοver="this.src='../Images/img/menu01_xz.jpg' " οnmοuseοut="this.src='../Images/img/menu01_dq.jpg' " />

1.花式连字符(&)

这个类应该在span元素里使用,并且里面包括&字符。它使用经典的serif字体和斜体来增强&符号。

?
1
2
3
4
5
6
7
8
9
.amp {
 
font-family : Baskerville, 'Goudy Old Style' , Palatino, 'Book Antiqua' , serif ;
 
font-style : italic ;

font-weight : normal ;
 
}

2.段落首字符下沉

通常,这种效果会出现在印刷媒体上,如报纸或书籍。同样,如果网页布局合理,它也可以使用在Web页面上,它仅针对段落使用,但你也可以与单个元素绑定。

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
p:first-letter{
 
display: block;
 
margin: 5px 0 0 5px;
 
float : left;
 
color: #ff3366;
 
font-size: 5.4em;
 
font-family: Georgia, Times New Roman, serif;
 
}

3.内层CSS3盒阴影

盒阴影(box shadow)属性几乎可以运用在任何元素上,它们看起来都非常好看。下面这段代码主要聚焦内层阴影的设计。

?
1
2
3
4
5
6
7
8
9
#mydiv {
 
-moz-box-shadow: inset 2px 0 4px #000 ;
 
-webkit-box-shadow: inset 2px 0 4px #000 ;
 
box-shadow: inset 2px 0 4px #000 ;
 
}

4.外层CSS3盒阴影

下面介绍一段外层阴影代码设计,注意,代码里的第三个参数表示模糊距离(blur distance),而第四个参数表示铺开的(spread)距离。关于这些值的设计,你可以前往 W3Schools学习。

?
1
2
3
4
5
6
7
8
9
#mydiv {
 
-webkit-box-shadow: 0 2px 2px -2px rgba( 0 , 0 , 0 , 0.52 );
 
-moz-box-shadow: 0 2px 2px -2px rgba( 0 , 0 , 0 , 0.52 );
 
box-shadow: 0 2px 2px -2px rgba( 0 , 0 , 0 , 0.52 );
 
}

5.三角形列表符号

该符号只能在CSS3里生成,在主流浏览器中,这是一项非常酷的技术。而其唯一的潜在问题是缺乏对后退方法的支持。

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
ul {
 
margin : 0.75em 0 ;
 
padding : 0 1em ;
 
list-style : none ;
 
}
 
li:before {
 
content : "" ;
 
border-color : transparent #111 ;
 
border-style : solid ;
 
border-width : 0.35em 0 0.35em 0.45em ;
 
display : block ;
 
height : 0 ;
 
width : 0 ;
 
left : -1em ;
 
top : 0.9em ;
 
position : relative ;
 
}

6.居中对齐并设置固定宽度

?
1
2
3
4
5
6
7
#page-wrap {
 
width : 800px ;
 
margin : 0 auto ;
 
}

7.CSS3列文本

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
#columns -3 {
 
text-align : justify ;
 
-moz-column-count: 3 ;
 
-moz-column-gap: 12px ;
 
-moz-column-rule: 1px solid #c4c8cc ;
 
-webkit-column-count: 3 ;
 
-webkit-column-gap: 12px ;
 
-webkit-column-rule: 1px solid #c4c8cc ;
 
}

8.固定页脚

在网页里添加固定的页脚其实非常简单,并且也很实用。有些网站的页脚设计得很漂亮,可以给网站呈现出一个完美的结尾。

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#footer {
 
position : fixed ;
 
left : 0px ;
 
bottom : 0px ;
 
height : 30px ;
 
width : 100% ;
 
background : #444 ;
 
}
 
/* IE 6 */
 
* html #footer {
 
position : absolute ;
 
top : expression(( 0 -(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+ 'px' );
 
}

9.IE 6下修复PNG格式的透明度

在网站里使用透明的图像已成为一种很普遍的做法,其始于.gif图片格式,但现在也涉及到.png图片格式。而一些老版本的IE不支持透明度,下面这段代码会很好地解决这一问题。

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
.bg {
 
width : 200px ;
 
height : 100px ;
 
background : url (/folder/yourimage.png) no-repeat ;
 
_background : none ;
 
_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src= '/folder/yourimage.png' ,sizingMethod= 'crop' );
 
}
 
/* 1px gif method */
 
img, .png {
 
position : relative ;
 
behavior: expression((this.runtimeStyle.behavior= "none" )&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf( '.png' )> -1 ?(this.runtimeStyle.backgroundImage = "none" ,
 
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')" ,
 
this.src = "images/transparent.gif" ):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace( 'url("' , '' ).replace( '")' , '' ),
 
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')" ,
 
this.runtimeStyle.backgroundImage = "none" )),this.pngSet=true));
 
}

10.跨浏览器设置最小高度

有时开发者需要对HTML元素设置最小高度,然而,这个效果却无法兼容IE和老版本的Firefox,下面这段代码可以修复这个问题。

?
1
2
3
4
5
6
7
8
9
#container {
 
min-height : 550px ;
 
height : auto !important ;
 
height : 550px ;
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值