- 主要應用了css3中border-radius屬性,分析以後把border-radius的屬性設置爲不同的邊角
- 絕對定位把div居中
- 應用translation屬性讓元素動起來
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding:0;
}
html,body{
/* 禁止scroll */
height: 100%;
overflow: hidden;
}
#wrap{
width: 300px;
height: 300px;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
transition: 2s;
}
#wrap>div{
margin: 10px;
width: 130px;
height: 130px;
border: 1px solid;
background-color: chartreuse;
float: left;
/* 不會破壞佈局 */
box-sizing: border-box;
}
#wrap>div:nth-child(1),#wrap>div:nth-child(4){
background-color: cornflowerblue;
border-radius: 0 60%;
}
#wrap>div:nth-child(2),#wrap>div:nth-child(3){
background-color: darkgray;
border-radius: 60% 0;
}
#wrap:hover{
transform: rotate(120deg);
}
</style>
</head>
<body>
<div id="wrap">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>