tôi đã viết giải pháp ít này:
/* screens range */
@screen-s-max: 20em; /* 320px */
@screen-min: 20.063em; /* 321px */
@screen-max: 40em; /* 640px */
@screen-m-min: 40.063em; /* 641px */
@screen-m-max: 64em; /* 1024px */
@screen-l-min: 64.063em; /* 1025px */
@screen-l-max: 90em; /* 1440px */
@screen-xl-min: 90.063em; /* 1441px */
@screen-xl-max: 120em; /* 1920px */
@screen-xxl-min: 120.063em; /* 1921px */
/*
0----- smallmobile -----320----- mobile -----640----- tablet -----1024----- notebook -----1440----- desktop -----1920----- wide
*/
@onlyScreen: ~"only screen";
@smallmobile: ~"(max-width: @{screen-s-max})";
@mobile: ~"(min-width: @{screen-s-max}) and (max-width: @{screen-max})";
@tablet: ~"(min-width: @{screen-m-min}) and (max-width: @{screen-m-max})";
@notebook: ~"(min-width: @{screen-l-min}) and (max-width: @{screen-l-max})";
@desktop: ~"(min-width: @{screen-xl-min}) and (max-width: @{screen-xl-max})";
@wide: ~"(min-width: @{screen-xxl-min})";
@portrait: ~"(orientation:portrait)";
@landscape: ~"(orientation:landscape)";
@highdensity: ~"only screen and (-webkit-min-device-pixel-ratio: 1.5)",
~"only screen and (min--moz-device-pixel-ratio: 1.5)",
~"only screen and (-o-min-device-pixel-ratio: 3/2)",
~"only screen and (min-device-pixel-ratio: 1.5)";
@mobile-and-more: ~"(min-width: @{screen-min})";
@tablet-and-more: ~"(min-width: @{screen-m-min})";
@notebook-and-more: ~"(min-width: @{screen-l-min})";
@desktop-and-more: ~"(min-width: @{screen-xl-min})";
/*
syntax example
@media @onlyScreen and @tablet and @portrait , @notebook and @landscape, @mobile and @landscape{
body{
opacity: 0.8;
}
}
*/
Như được trình bày trong ví dụ cú pháp, bạn có thể kết hợp tất cả các biến ít hơn và nhận truy vấn phương tiện phức tạp. Sử dụng "và" cho toán tử logic AND và dấu phẩy cho OR. Bạn có thể kết hợp các độ phân giải màn hình khác nhau, hướng thiết bị (ngang/dọc) và võng mạc hoặc không phải thiết bị.
Mã này cũng dễ cấu hình được vì bạn có thể chỉnh sửa/thêm/loại bỏ các giá trị phạm vi màn hình để quản lý độ phân giải màn hình khác nhau.
Bắt đầu bằng thiết bị di động trước, sau đó mở rộng chế độ xem của bạn cho đến khi thiết kế bị hỏng hoặc trông có vẻ xấu, thêm điểm ngắt ... lặp lại. – justinavery
Ít hơn: Tôi làm theo cách khác, bắt đầu với tỷ lệ phần trăm đáp ứng dựa trên máy tính để bàn và thêm ngoại lệ cho thiết bị di động và máy tính bảng - thường có nghĩa là chỉ tinh chỉnh lưới, như tạo kiểu cho tất cả các cột thành chiều rộng –