css六邊形效果程式碼例項

螞蟻小編發表於2017-04-16

分享一段程式碼例項,它實現了六邊形效果。

程式碼如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
* {
  margin: 0;
  padding: 0;
}
/*css*/
.ant {
  position: relative;
  width: 200px;
  height: 120px;
  background-color: red;
  margin: 100px;
}
.ant:after {
  content: "";
  position: absolute;
  display: block;
  top: -160px;
  width: 0;
  height: 0;
  border: 100px solid transparent;
  border-bottom: 60px solid red;
}
.ant:before {
  content: "";
  position: absolute;
  display: block;
  bottom: -160px;
  width: 0;
  height: 0;
  border: 100px solid transparent;
  border-top: 60px solid red;
}
</style>
</head> 
<body> 
  <div class="ant"></div>
</body> 
</html>

相關文章