Can we use the ">" or "<" symbols(Greater than and Less than ) in media queries? for example I would like to hide a dive for all monitors less than 768px. can I say some thing like this:
@media screen and (min-width<=768px) {}
Can we use the ">" or "<" symbols(Greater than and Less than ) in media queries? for example I would like to hide a dive for all monitors less than 768px. can I say some thing like this:
@media screen and (min-width<=768px) {}
Media queries don't make use of those symbols. Instead, they use the
min-
andmax-
prefixes. This is covered in the spec:So, instead of something like
(width <= 768px)
, you would say(max-width: 768px)
instead:Check out the Sass lib include-media, which (despite being for Sass) explains how calls like
@include media('<=768px')
maps to plain CSS@media
queries. In particular, see this section of the docs.TLDR, what you learn from there is:
To do the equivalent of something like
media('<=768px')
(less than or equal to 768) in CSS, you need to writeand to do the equivalent of
media('<768px')
(less than 768) in CSS, you need to writeNotice how I subtracted
1
from768
, so that the max width is less than 768 (because we wanted to emulate the<
less-than behavior which doesn't actually exist in CSS).So to emulate something like
media('>768px', '<=1024')
in CSS, we would write:and
media('>=768px', '<1024')
would be