"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Can I Use "OR" Logic to Combine Multiple Conditions in CSS Media Queries?

How Can I Use "OR" Logic to Combine Multiple Conditions in CSS Media Queries?

Published on 2024-12-21
Browse:296

How Can I Use

Combining Multiple Conditions in CSS Media Queries with OR Logic

In CSS media queries, specifying multiple conditions using "OR" logic can be useful for targeting devices with different screen sizes or aspects. While the code provided in the question is incorrect, there is a straightforward method to achieve the desired result.

To specify multiple conditions with "OR" logic, separate them with commas:

@media screen and (max-width: 995px), screen and (max-height: 700px) {
  ...
}

As explained in the documentation at https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries:

"Commas are used to combine multiple media queries into a single rule. Each query in a comma-separated list is treated separately from the others. Thus, if any of the queries in a list is true, the entire media statement returns true. In other words, lists behave like a logical or operator."

Using this approach, the media query checks if the screen width is less than or equal to 995 pixels or if the screen height is less than or equal to 700 pixels. If either condition is met, the styles specified within the media query will be applied.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3