Toggle navigation
☰
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <style> .abs-container { /* We define a negative variable */ --dynamic-offset: -150px; background-color: #f8f9fa; border: 1px solid #dee2e6; padding: 20px; height: 200px; display: flex; align-items: center; justify-content: center; } .abs-box { background-color: #0d6efd; color: white; font-family: sans-serif; font-weight: bold; display: flex; align-items: center; justify-content: center; text-align: center; height: 100px; border-radius: 8px; /* 1. We use the negative value directly to translate the box to the left. 2. We use abs() to convert the negative value to a positive 150px for the width. (If we just used width: var(--dynamic-offset), the width would be invalid and default to auto!) */ transform: translateX(var(--dynamic-offset)); width: abs(var(--dynamic-offset)); } </style> <div class="abs-container"> <div class="abs-box"> Moved -150px<br> Width 150px </div> </div>