Toggle navigation
☰
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <style> .tan-container { background-color: #f8f9fa; border: 1px solid #dee2e6; padding: 40px; border-radius: 8px; display: flex; justify-content: center; /* Define our known width and our desired angle */ --base-width: 200px; --angle: 30deg; } .tan-box { position: relative; background-color: #e9ecef; border: 2px solid #6c757d; width: var(--base-width); /* Calculate the unknown height using tan(). Formula: Height = Width * tan(Angle) */ height: calc(var(--base-width) * tan(var(--angle))); transition: height 0.5s ease; cursor: pointer; } .diagonal-line { position: absolute; bottom: 0; left: 0; width: 200%; /* Make it extra long so it covers the distance */ height: 2px; background-color: #0d6efd; transform-origin: bottom left; /* Rotate the line to match our angle */ transform: rotate(calc(var(--angle) * -1)); transition: transform 0.5s ease; } .label { position: absolute; top: 10px; left: 10px; font-family: sans-serif; font-size: 0.85em; font-weight: bold; color: #343a40; } /* Change the angle on hover to see the height recalculate */ .tan-container:hover .tan-box { --angle: 45deg; } </style> <div class="tan-container"> <div class="tan-box"> <div class="diagonal-line"></div> <div class="label">Hover to change angle</div> </div> </div>