-
CSS Grid Expanding Box animation
HTML
CSS
JavaScript
body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #000; } .cube-container { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; width: 300px; height: 300px; transition: all 0.7s cubic-bezier(0.16, 1, 0.3, 1); overflow: hidden; border-radius: 30px; } .box { display: flex; justify-content: center; align-items: center; color: white; cursor: pointer; transition: all 0.7s cubic-bezier(0.16, 1, 0.3, 1); position: relative; } /* --- ICON SIZE INCREASE --- */ .box i { width: 64px; height: 64px; stroke-width: 2.5px; transition: transform 0.7s ease, filter 0.3s ease; } /* Grid Expansion Logic */ .cube-container:has(.box-1:hover) { grid-template-columns: 1fr 0fr; grid-template-rows: 1fr 0fr; } .cube-container:has(.box-2:hover) { grid-template-columns: 0fr 1fr; grid-template-rows: 1fr 0fr; } .cube-container:has(.box-3:hover) { grid-template-columns: 1fr 0fr; grid-template-rows: 0fr 1fr; } .cube-container:has(.box-4:hover) { grid-template-columns: 0fr 1fr; grid-template-rows: 0fr 1fr; } /* --- HOVER SCALE INCREASE --- */ .box:hover i { transform: scale(5); filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3)); } .box-1 { background-color: #8b5cf6; } .box-2 { background-color: #3b82f6; } .box-3 { background-color: #f43f5e; } .box-4 { background-color: #10b981; }
Live Preview