您好,欢迎访问一九零五行业门户网

CSS实现三角形标记的方法介绍

本篇文章将给大家分享关于css实现三角形标记的方法,内容很详细,有需要的朋友参考一下。
话不多说,我们先来直接看代码~
代码如下:
cssmark.html
<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title></title> <link rel="stylesheet" type="text/css" href="cssmark.css" /> </head> <body> <div class="trimarkpre0"></div> <br /> <div class="trimarkpre1"></div> <br/> <div class="trimarkpre2"></div> <br /> <div class="trimark"></div> </body> </html>
cssmark.css
.trimarkpre0 { position: static; width: 100px; height: 100px; border: 10px solid transparent; border-color: #0058e2;}.trimarkpre1 { position: static; width: 100px; height: 100px; border: 10px solid transparent; border-left-color: #0058e2;}.trimarkpre2 { position: static; width: 0px; height: 0px; border: 10px solid transparent; border-left-color: #0058e2;}.trimark { position: static; width: 0px; height: 0px; border: 5px solid transparent; border-left-color: #0058e2;}
代码详解
创建流程1:
下面的代码是绘制100 x 100像素区域的外框的代码。这是一般代码。
执行结果图像顶部的方框对应于该代码。
<div class="trimarkpre0"></div>
.trimarkpre0 { position: static; width: 100px; height: 100px; border: 10px solid transparent; border-color: #0058e2;}
创建过程2:
使用下面的代码,仅绘制区域框架的左侧。如果您绘制左侧,您可以看到拐角部分是对角切割的。(当绘制4个边时,只绘制一半以使每条线不重叠。)
此代码对应于将执行结果图像的第二个梯形向侧面的代码。
<div class="trimarkpre1"></div>
.trimarkpre1 { position: static; width: 100px; height: 100px; border: 10px solid transparent; border-left-color: #0058e2;}
完成:
可以使用以下代码绘制三角形标记。
通过减小前一行左侧代码的高度,行之间的部分将消失,它将显示为三角形标记。
执行结果图像的第三个图对应于该代码。
<div class="trimarkpre2"></div>
.trimarkpre2 { position: static; width: 0px; height: 0px; border: 10px solid transparent; border-left-color: #0058e2;}
您可以通过减小线的边框宽度来更改三角形标记的大小。
执行结果图像的第四个图对应于该代码。
<div class="trimark"></div>
.trimark { position: static; width: 0px; height: 0px; border: 5px solid transparent; border-left-color: #0058e2;}
执行结果:
显示html文件时,将显示下图。
补充:
您可以通过更改要绘制的边框的位置来更改三角形的方向。
代码如下:
cssmark2.html
<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title></title> <link rel="stylesheet" type="text/css" href="cssmark.css" /> </head> <body> <div class="trimarkright"></div> <br /> <div class="trimarkleft"></div> <br /> <div class="trimarktop"></div> <br /> <div class="trimarkbotom"></div> </body> </html>
cssmark.css
.trimarkright { position: static; width: 0px; height: 0px; border: 15px solid transparent; border-left-color: #0058e2;}.trimarkleft { position: static; width: 0px; height: 0px; border: 15px solid transparent; border-right-color: #0058e2;}.trimarktop { position: static; width: 0px; height: 0px; border: 15px solid transparent; border-bottom-color: #0058e2;}.trimarkbotom { position: static; width: 0px; height: 0px; border: 15px solid transparent; border-top-color: #0058e2;}
效果如下:
以上就是css实现三角形标记的方法介绍的详细内容。
其它类似信息

推荐信息