下面是一些利用CSS中border的特性绘制的各种角度的三角形:
代码如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-left: 50px solid gray;
- border-right : 50px solid green;
- border-bottom: 50px solid red;
- border-top : 50px solid yellow;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
如上图1,由于设置了width、height都为0了,所以四个点也就归并成了一个点,后面的各种角度的三角形,其实也就是不断调整那个中心点而已。
代码如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-left: 50px solid transparent;
- border-right : 50px solid transparent;
- border-bottom: 100px solid red;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-left: 50px solid transparent;
- border-right : 50px solid transparent;
- border-top: 100px solid red;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
代码如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-right: 100px solid red;
- border-top : 50px solid transparent;
- border-bottom: 50px solid transparent;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
代码如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-left: 100px solid red;
- border-top : 50px solid transparent;
- border-bottom: 50px solid transparent;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-top : 100px solid red;
- border-right: 100px solid transparent;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
代码如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-top : 100px solid red;
- border-left: 100px solid transparent;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
代码如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-bottom : 100px solid red;
- border-right: 100px solid transparent;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
代码如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>index</title>
- <style type="text/css">
- #triangle {
- width : 0;
- height: 0;
- border-bottom : 100px solid red;
- border-left: 100px solid transparent;
- }
- </style>
- </head>
- <body>
- <div id="triangle"></div>
- </body>
- </html>
评论