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