代碼如下:

<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>用CSS畫一個三角形</title>
<style>
#triangle {
width:0;height:0;
border-top:100px solid green;
border-right:100px solid red;
border-bottom:100px solid black;
border-left:100px solid blue;
}
</style>
</head>
<body> <div id='triangle'></div>
</body>
</html>

效果如圖:

幾個注意:div寬度,高度分別爲0,而div邊框的寬度設定,這時可以看到四個三角形,那麼我們要取哪一個三角形,就需要讓其他三角的邊框的顏色爲透明?

爲什麼是透明,而不是白色呢??

因爲如果是白色,而三角型所在的區域同時又有背景色,那麼在三角型的區域就會把背景顏色覆蓋。

如下圖:

三角形白色部分把背景顏色覆蓋了!Error!

那麼如何讓邊框變透明呢??

答案就是border-color屬性中的默認值:transparent

<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>用CSS畫一個三角形</title>
<style>
div.bg {
background-color:maroon;
height:500px;
}
#triangle {
width:0;height:0;
border-top:100px solid transparent;
border-right:100px solid transparent;
border-bottom:100px solid black;
border-left:100px solid transparent;
}
</style>
</head>
<body> <div class='bg'>
<div id='triangle'></div>
</div>
</body>
</html>

效果如圖:

三角形成功出現,現在可以做一個模型了,比如tips,warnings.

  

最新文章

  1. Failed opening .rdb for saving: Permission denied
  2. 免费下载!Twitter Bootstrap V3 矢量界面素材
  3. 重构第18天 用条件语句来代替异常(Replace exception with conditional)
  4. 集成 AliPay - 支付宝
  5. [Papers]NSE, $u_3$, Lebesgue space [Kukavica-Ziane, Nonlinearity, 2006]
  6. js--Ajax的小知识(二):处理ajax的session过期的请求
  7. 一个短路求值引起的一个小bug
  8. 常用文件的文件头(附JAVA测试类)
  9. DataBase MongoDB集群方案介绍
  10. java ecplise配置
  11. 关于 minor allele frequency(次等位基因频率)的理解
  12. JUI/DWZ 分页 Servlet
  13. 关于C#传给视图的字符串带有Html转义字符的处理
  14. python输入字符串
  15. 听说https更安全
  16. C++ WINDOWS下 wchar_t *和char * 相互转化总结篇
  17. windows powershell
  18. Python的Numpy库简述
  19. 【GitLab】gitlab上配置webhook后,点击测试报错:Requests to the local network are not allowed
  20. 匹配&lt;a href=&quot;url&quot;&gt;content&lt;/a&gt;

热门文章

  1. 对线程调度中Thread.sleep(0)的深入理解
  2. hdu 5188 dfs+二分
  3. matlab练习程序(透视投影,把lena贴到billboard上)
  4. Android中Dialog
  5. 内容提供者Content Provider
  6. php二位数组合并
  7. include、include_once与require、require_once区别
  8. velocity 判断 变量 是否不是空或empty
  9. [Unity2D]精灵
  10. 像jQuery那样,采用链式方法,封装一个方法:CSS()