Home > Web Front-end > HTML Tutorial > 如何利用CSS实现三角形效果_html/css_WEB-ITnose

如何利用CSS实现三角形效果_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:31:40
Original
961 people have browsed it

如何利用CSS实现三角形效果:
建议:尽可能的手写代码,可以有效的提高学习效率和深度。
有时候我们经常发现有些矩形的某个地方会出现三角形效果,感觉挺神奇的,当然可以使用背景图片实现,这里简单介绍一下不采用背景图片的效果。代码如下:

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.parent{  width:300px;  height:100px;  margin:40px auto;  background-color:green;  position:relative;}.square{  width:0px;  height:0px;  border-bottom:10px solid white;  border-left:10px solid white;  border-right:10px solid green;  border-top:10px solid green;  position:absolute;  left:-20px;  top:10px;}</style></head><body><div class="parent">  <div class="square"></div></div></body></html>
Copy after login

原理很简单,可能上面的代码还不够明显,那么请看下面这个代码实例就一目了然了。

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">div{  width:0px;  height:0px;  border-bottom:10px solid green;  border-left:10px solid blue;  border-right:10px solid red;  border-top:10px solid black;}</style></head><body><div></div></body></html>
Copy after login

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4650

更多内容可以参阅:http://www.softwhy.com/divcss/

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template