面试图如下:不用任何图片,实现这个效果:

不用图片来实现不规则图形的效果,首先想到的是使用border。先把代码送上:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
   body,div{margin:0;padding:0;}
   .tb {margin:30px auto;height:0;width:0;overflow:hidden;border-left:80px #fff solid;border-right:80px #fff solid;border-top:none;border-bottom:80px blue solid;}
</style>
</head>
<body> 
<div class="tb">
</div>
</body>
</html>

代码十分简单,关键是为什么要使用border,怎么使用border。为了简单易见,我们先做一个宽高都为200px,边为50px宽,并且四边颜色不一样的div。注意看各个边的交接处。

从这个图不难看出,1:交接处是斜边,如果把各个边的粗细发生变化,倾斜的角度也会有所不同。

2:如果把内容部分的宽、高、padding都设置为0;则每个单边都是一个三角形。

3:理论上可以用边框可以拼成任何的几何图形(使用position定位的情况下)

下面是两个边框做成的图形的例子。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
   body,div{margin:0;padding:0;}
   .t {width:400px;height:400px;margin:50px auto;overflow:hidden;}
   .t div {height:100px;width:100px;float:left;}
   .t1 {border-top:50px #fff solid;border-right:50px red solid;border-bottom:50px red solid;border-left:50px #fff solid;}
   .t2 {border-top:50px #fff solid;border-right:50px #fff solid;border-bottom:50px red solid;border-left:50px red solid;}
   .t3 {border-top:50px red solid;border-right:50px red solid;border-bottom:50px #fff solid;border-left:50px #fff solid;}
   .t4 {border-top:50px red solid;border-right:50px #fff solid;border-bottom:50px #fff solid;border-left:50px red solid;}
</style>
</head>
<body>
<div class="t">
<div class="t1">
</div>
<div class="t2">
</div>
<div class="t3">
</div>
<div class="t4">
</div>
</div>
</body>
</html>

效果如下:



再来一个效果:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
   body,div{margin:0;padding:0;}
   .t1 {width:0;height:0;overflow:hidden;border-top:200px red solid;border-right:120px transparent solid;border-bottom:none;border-left:120px transparent solid;margin:100px auto 0;}
   .t2 {width:0;height:0;overflow:hidden;border-bottom:200px red solid;border-right:120px transparent solid;border-top:none;border-left:120px transparent solid;margin:-270px auto 0;}
</style>
</head>
<body>

<div class="t1">
</div>
<div class="t2">
</div>

</body>
</html>

(注:因为用了比较偷懒的方法两个三角形叠压,使用透明边框,ie6不支持,或者使用3个div从上往下排液比较简单)