css用伪类如何制作左右箭头三角形

html-css09

css用伪类如何制作左右箭头三角形,第1张

我在另一个问题里面涉及到了这个,你可以参考一下。网页链接

伪类你也可以理解为一个容器,不过为了展示顺利需要添加   content: ''和display:block;为了能够准确定位,需要结合其容器设置定位,这都是基础不需要多介绍。

使用伪类做左右的箭头主要是需要了解 边框的构成

{

 border: 20px solid #333

   border-top-color: #369

   border-bottom-color: red

   border-left-color: green

   border-radius: 0

}

如图,我用四个颜色分别给四条边上色,可以看出来每一个边在宽度大于1的时候表现出的样子就倾向于一个梯形。

而我们可以理解为三角形其实就是梯形的一条底边长度为零。

那么为了得到一个三角形那么我们只需要容器的宽高都为零就可以了,如图:

 {

   border: 20px solid #333

   border-top-color: #369

   border-bottom-color: red

   border-left-color: green

   border-radius: 0

   font-size: 0

   width: 0

   height: 0

   padding: 0

}

下一步我们只留下一个三角形。

只要让不需要展示的边颜色为透明就可以了

{

   border: 20px solid transparent

   /* border-top-color: #369 */

   /* border-bottom-color: red */

   border-left-color: green

   border-radius: 0

   font-size: 0

   width: 0

   height: 0

   padding: 0

}

这样你拿到的是上下左右四个方向的三角形,同样的 你如果需要的是斜向右上角的或者其他角度的,只要自己凑出这个方向就可以,类似于七巧板。

如果希望三角形呈现的不是直角三角形可以修改各个边的宽度。。

{

   border: 20px solid transparent

   border-top-color: #369

   /* border-bottom-color: red */

   border-left-color: green

   border-radius: 0

   font-size: 0

   width: 0

   height: 0

   padding: 0

}

图片中的箭头用的都是背景图片。

先找到保存这些图片下来,然后再写相应的CSS。

css背景代码:

background:url(bgimage.jpg) no-repeat -2px 0px //后面的-2px 0px可以去掉或者调整相应的图片坐标位置

<!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/htmlcharset=utf-8" />

<title>鼠标形状</title>

<style>

* {margin:0padding:0}

ul {width:250pxmargin:50px autoborder:1px solid #f00border-bottom:none}

li {width:250pxheight:30pxline-height:30pxtext-align:centerlist-style:nonebackground:#000border-bottom:1px solid #f00color:#ffffont-weight:bold}

</style>

</head>

<body>

<ul>

<li style="cursor:pointer">pointer 手型</li>

<li style="cursor:crosshair">crosshair 十字</li>

<li style="cursor:text">text 文本</li>

<li style="cursor:wait">wait 等待</li>

<li style="cursor:help">help 问号</li>

<li style="cursor:move">move 移动</li>

<li style="cursor:e-resize">e-resize 右的箭头</li>

<li style="cursor:ne-resize">ne-resize 右上的箭头</li>

<li style="cursor:n-resize">n-resize 上的箭头</li>

<li style="cursor:nw-resize">nw-resize 左上的箭头</li>

<li style="cursor:w-resize">w-resize 左的箭头</li>

<li style="cursor:sw-resize">sw-resize 左下的箭头</li>

<li style="cursor:s-resize">s-resize 下的箭头</li>

<li style="cursor:se-resize">se-resize 右下的箭头</li>

</ul>

</body>

</html>