Tìm hiểu về Aspect Ratio với CSS
RUN
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> .main { width: 50%; margin: auto; } .container { background-color: red; position: relative; width: 100%; padding-top: 56.25%; /* Tỉ lệ 16:9 */ } .text { position: absolute; top: 0; left: 0; bottom: 0; right: 0; text-align: center; font-size: 20px; color: white; } </style> </head> <body> <div class="main"> <h2>Freetuts.net - Tìm hiểu về Aspect Ratio</h2> <p>Thay đổi kích thước trình duyệt để xem hiệu ứng</p> <div class="container"> <div class="text">Tỉ lệ 16:9</div> </div> </div> </body> </html>
PHÓNG TO