请问:css如何实现一个向下的三角形边框(border)?不明白的可以看下面图例。谢谢!

html-css014

请问:css如何实现一个向下的三角形边框(border)?不明白的可以看下面图例。谢谢!,第1张

根据你的图片,达到这种效果有2种方法:

1.用图片png图片作为背景;

2.可以用纯css就可以达到,举个例子:

<!DOCTYPE html>

<html>

<head>

  <meta charset="UTF-8">

  <title>Document</title>

<style type="text/css">

body{

  background-color: #444

}

.test{

  width: 15px

  height: 30px

  box-sizing:border-box

  border-top: 15px solid #f5f5f5

  border-bottom: 15px solid #f5f5f5

  /*border-left: 20px solid #0f0*/

  border-right: 15px solid transparent

 /* border-top-right-radius: 4px

  border-radius: 12px*/

}

.csspic{

  width: 200px

  height: 400px

  margin:50px auto

  background:  url(images/5.jpg) -15px top no-repeat

  -webkit-background-size: cover

  background-size: cover

  border-radius: 10px

  position: relative

  border: 15px solid #f5f5f5

  -moz-background-clip: border

  -webkit-background-clip: border-box

  -o-background-clip: border-box

  background-clip: border-box

}

.img{  

  overflow: hidden

  width: 260px

  height: 400px

}

.sjx{

  position: absolute

  top:30px

  left: -15px

  background:  url(images/5.jpg) left -30px no-repeat

  -webkit-background-size: 500px

  background-size: 500px

  z-index: 9999

}

.csspic img{

  height: 100%

}

</style>

</head>

<body>

  <div class="csspic">

      <div class="sjx">

          <div class="test"></div>

      </div>

      <div class="img"><!-- <img src="images/5.jpg">--></div>

   

  </div>

</body>

</html>

当div宽度为0,高度为0的时候,只设置border的大小和四边不同颜色可看到下图,只保留一边的颜色,另外三边的颜色设置为transparent可得到一个方向的三角形。因此,可延伸出设置一边的border的颜色,相邻两边的border设置为transparent可得到一个方向的三角形。

border的大小的值为三角形底边上的高,三角形的底为相邻两边的border的高的和,如下图所示的红色锐角三角形

若想实现直角三角形的效果,如下图所示直角在左上的三角形,按原理可设置上border和左border的颜色,另外两条边的颜色为transparent,此样式可简写为只设置上border的颜色,另一条相邻的右border为transparent

你也许会遇到要画个奇怪三角形的时候,只要参考锐角三角形的方式,找到三角形底边和高,计算出三角形高和把相邻两条边的高相加作为底部,你可以画出各种各样的三角形,如果再加上角度旋转的css,你便啥三角形都能画!

此类三角形解决思路通常使用两个不同颜色的三角形做颜色叠加,比如做如上图所示的边框为1px的红色边框白色底三角形,就先画一个红色三角形,再画一个尺寸少2px的白色底三角形,然后设置两个三角形的position将三角形重叠,这里使用伪元素实现

1、向上正箭头

2、向下正箭头

3、向左正箭头

4、向右正箭头

5、向左上箭头

6、向右上箭头

7、向左下箭头

8、向右下箭头