css3如何实现边框阴影

2024-10-12 08:20:24

利用边框阴影(box-shadow),可以制作出光晕、浮雕等原来只有依赖P图才能完成的效果。ie6~ie8都不支持边框阴影(box-shadow),ie9+Firefox4,Chrome,Opera及Safari5.1.1支持边框阴影属性(box-shadow)

css3如何实现边框阴影

2、内外阴影在边框阴影(box-shadow)的基本语法中,参数inset是可选可不选的,选参数inset,将外部阴影改为内部阴影;而不选参数inset,即默认情况下是外部阴影的。例子:css部分:.div2{ width:200px; height:200px; margin:50px auto; line-height: 200px; text-align: center; background: burlywood; border:2px solid #e4007e; box-shadow: darkgrey 0px 0px 30px 5px inset;//边框内阴影 }html部分:<div class="div2">边框内阴影示例</div>效果如图(对比内外阴影效果):

css3如何实现边框阴影

3、偏移量(h-shadow 、 v-shadow)在上面第二步的基础上添加水平和垂直10px的偏移量。对于外阴影,偏移量相当于从图形的正后方,向右下进行了偏移;而对于内阴影,偏移量相当于图形内部没有被阴影覆盖的部分向右下进行了偏移。例子:css部分:.div2{ width:200px; height:200px; margin:50px auto; line-height: 200px; text-align: center; background: burlywood; border:2px solid #e4007e; box-shadow: darkgrey 10px 10px 30px 10px inset;//边框内阴影 }html部分:<div class="div2">边框外阴影示例</div>效果如图(对比内外阴影偏移量的区别):

css3如何实现边框阴影

4、阴影尺寸(耩撞苏粪参数spread)阴影尺寸就是指阴影外延出去总的长度。将除阴影尺寸以外的值都设置为0,就能直观的查看阴影尺寸。例子:css部分:.div3{ wi颊俄岿髭dth:200px; height:200px; margin:50px auto; line-height: 200px; text-align: center; background: salmon; border:2px solid #e4007e; box-shadow: darkgrey 0px 0px 0px 10px inset; } .div4{ width:200px; height:200px; margin:50px auto; line-height: 200px; text-align: center; background: salmon; border:2px solid #e4007e; box-shadow: darkgrey 0px 0px 0px 10px; }html部分:<div class="div3">边框内阴影尺寸示例</div><div class="div4">边框外阴影尺寸示例</div>效果如图:

css3如何实现边框阴影css3如何实现边框阴影
猜你喜欢