Media Queries
Media Queries allow us to define CSS styling rules for web page elements by querying on on the device type and/or certain features of the device on which the web content is currently being viewed or rendered.
In a single media style rule, multiple queries for device types or features can be combined using logical operators - and
, not
or only
.
Syntax for writing a CSS Media rules: @media <<device type or feature query or comma-separated list of queries>> <<logical operator>> <<device type or feature query or comma-separated list of queries>>....
examples:
Using CSS media query for Responsive Web Design (RWD):
Below css media rules define how our web content would be rendered on devices of type screen
and different sizes - usually we target
Also note, usually, we add below viewport
tag in the header of our page HTML to have it respond to device screen size on phones or tablet:
This tells the device that the content of the web page needs to be equal to the device width and keep the contents initial scale to 100% and do not scale it up or down.
Last updated