Toggle navigation
☰
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <style> .hypot-container { /* Define the dimensions of our box */ --box-width: 300px; --box-height: 150px; width: var(--box-width); height: var(--box-height); background-color: #f8f9fa; border: 2px solid #343a40; margin: 0 auto; position: relative; overflow: hidden; } .diagonal-line { position: absolute; top: 0; left: 0; height: 4px; background-color: #dc3545; transform-origin: top left; /* 1. Use hypot() to calculate the exact diagonal length. 2. Use atan2() to calculate the exact angle to point to the bottom-right corner. */ width: hypot(var(--box-width), var(--box-height)); transform: rotate(atan2(var(--box-height), var(--box-width))); } .label { position: absolute; bottom: 10px; left: 10px; font-family: sans-serif; font-size: 0.9em; color: #6c757d; } </style> <div class="hypot-container"> <div class="diagonal-line"></div> <div class="label">Width: 300px | Height: 150px</div> </div>