实现一个八边形
一、背景八边形
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.box {
width: 240px;
height: 240px;
position: relative;
overflow: hidden;
padding: 20px;
}
.box::before{
content: '';
background-color: #f00;
position: absolute;
left: -35px;
right: -35px;
top: -35px;
bottom: -35px;
transform: rotate(45deg);
z-index: -1;
}
</style>
</head>
<body>
<div class='box'>content</div>
</body>
</html>
结果
#######################################################################################
二、边框八边形
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
.box {
margin: 50px;
}
.box {
box-sizing: border-box;
width: 340px;
height: 340px;
position: relative;
overflow: hidden;
}
.box::before{
content: '';
background-color: #f00;
position: absolute;
left: -35px;
right: -35px;
top: -35px;
bottom: -35px;
transform: rotate(45deg);
z-index: -1;
}
.core {
box-sizing: border-box;
padding: 25px;
width: 338px;
height: 338px;
overflow: hidden;
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.core::before{
content: '';
background-color: #FFF;
position: absolute;
left: -35px;
right: -35px;
top: -35px;
bottom: -35px;
transform: rotate(45deg);
z-index: -1;
}
</style>
</head>
<body>
<div class='box'>
<div class="core">content</div>
</div>
</body>
</html>