Using Logical Operators in CSS Media Queries
CSS media queries support logical operators such as and, not, and only to combine or restrict conditions for applying styles. These operators allow developers to create precise and complex responsive design rules that target specific scenarios.
and — Combines multiple conditions so that all must be true for the styles to apply.
not — Excludes styles from applying when a certain condition is true.
only — Prevents older browsers that do not support media queries from applying the contained styles.
In this example, and ensures styles apply only when both conditions match, not excludes certain viewports, and only safeguards modern media query syntax from older browsers. These logical operators make media queries more powerful and flexible in responsive design.