device-aspect-ratio

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Note: Để truy vấn aspect ratio của khung nhìn (viewport), các nhà phát triển nên sử dụng tính năng media aspect-ratio thay thế.

Tính năng media device-aspect-ratio trong CSS có thể được dùng để kiểm tra aspect ratio chiều rộng so với chiều cao của thiết bị đầu ra.

Cú pháp

Tính năng device-aspect-ratio được chỉ định dưới dạng giá trị <ratio>. Đây là tính năng phạm vi, nghĩa là bạn cũng có thể dùng các biến thể có tiền tố min-device-aspect-ratiomax-device-aspect-ratio để truy vấn giá trị nhỏ nhất và lớn nhất tương ứng.

Ví dụ

Sử dụng min-device-aspect-ratio

css
article {
  padding: 1rem;
}

@media screen and (min-device-aspect-ratio: 16/9) {
  article {
    padding: 1rem 5vw;
  }
}

Đặc tả

Thông số kỹ thuật
Media Queries Level 4
# device-aspect-ratio

Tương thích trình duyệt