css实现一个六边形布局效果代码
代码语言:html
所属分类:布局界面
代码描述:css实现一个六边形布局效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html, body { height: 100%; } body { display: flex; align-items: center; justify-content: center; } #board { display: grid; grid-template-columns: 1fr; grid-template-rows: repeat(5, 1fr); justify-items: center; position: relative; width: 80vh; height: 80vh; } @media (max-width: 100vh) { #board { width: 80vw; height: 80vw; } } #board::before { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 100%; background-color: #eae9cc; transform: scale(1.15, 1.075); -webkit-clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%); clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%); z-index: -2; } #board::after { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 100%; transform: scale(1.15, 1.075); -webkit-clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%); clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%); z-index: -1; } #board .hex-row { display: grid; grid-template-rows: 1fr; justify-content: center; position: relative; padding: 1px; } #board .hex-row:nth-child(1) { top: 40%; grid-template-columns: repeat(3, 1fr); width: 60%; } #board .hex-row:nth-child(2) { top: 20%; grid-template-columns: repeat(4, 1fr); width: 80%; } #board .hex-row:nth-child(3) { top: 0%; grid-template-columns: repeat(5, 1fr); width: 100%; } #board .hex-row:nth-child(4) { top: -20%; grid-template-columns: repeat(4, 1fr); width: 80%; } #board .hex-row:nth-child(5) { top: -40%; grid-template-columns: repeat(3, 1fr); width: 60%; } #board .hex-row .hex { padding: 1px; background-color: tan; background-size: cover; background-position: center; transform: scale(1.015); -webkit-clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); } .hex3 { background: red; -webkit-clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%); clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%); } .hex4 { background: blue; -webkit-clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); } button { display: block; padding: 5px 10px; position: fixed; bottom: 15px; left: 50%; -webkit-appearance: none; -moz-appearance: none; appearance: none; background-color: #2196f3; border: none; border-radius: 500px; box-shadow: 0 5px 10px -5px rgba(0, 0, 0, 0.5); color: #fff; tran.........完整代码请登录后点击上方下载按钮下载查看
网友评论0