Purpose of Media Queries
Which option best describes how CSS media queries enable responsive design? For example, consider adapting a website layout for smartphones and desktops.
- They let you apply CSS rules based on device characteristics such as width or orientation.
- They provide JavaScript functions to handle browser resizing.
- They can only switch between light and dark themes automatically.
- They trigger alert messages based on user input.
- They exclusively optimize images for different network speeds.
Media Types Syntax
How would you write a media query that applies styles only for print devices?
- @media print { /* styles */ }
- @media paper { /* styles */ }
- @media device:print { /* styles */ }
- @media printed { /* styles */ }
- @media (print) { /* styles */ }
Combining Media Features
Given the desire to target screens in landscape orientation with a maximum width of 990px, which media query is correct?
- @media (max-width: 990px) and (orientation: landscape) { }
- @media (max-width: 990px), (orientation: landscape) { }
- @media [max-width: 990px] u0026 [orientation: landscape] { }
- @media (maxwidth: 990px) and (orientation: landscape) { }
- @media screen and orientation: landscape and max-width: 990px { }
Logical Operators in Media Queries
Which logical operator would you use in a media query to apply CSS only if multiple conditions are simultaneously true?
- and
- or
- not
- nor
- only
Breakpoints in Responsive Design
In responsive design, what is a 'breakpoint'? For example, changing from two columns to one when the screen becomes narrower.
- A defined screen width where the website layout changes
- A CSS property that breaks the stylesheet into pieces
- A JavaScript event fired on screen resize
- A browser tool used to debug layouts
- A point where server-side rendering stops
Mobile-First Approach
Which code snippet demonstrates a mobile-first approach to media queries?
- .container { width: 100%; } @media (min-width: 600px) { .container { width: 50%; } }
- @media (max-width: 600px) { .container { width: 100%; } } .container { width: 50%; }
- .container { width: 100%; } @media (max-width: 600px) { .container { width: 50%; } }
- @media (min-width: 600px) { .container { width: 100%; } } .container { width: 50%; }
- @media (min-width: 600px) and (max-width: 800px) { .container { width: 100%; } }
Nesting Media Queries
How can you apply a CSS media query to affect only a specific class, for example, '.wrapper'?
- .wrapper { /* default styles */ } @media (max-width: 800px) { .wrapper { /* responsive styles */ } }
- @media (max-width: 800px) and (.wrapper) { /* styles */ }
- .wrapper @media (max-width: 800px) { /* responsive styles */ }
- .wrapper { @media (max-width: 800px) { /* responsive styles */ } }
- @media (.wrapper) and (max-width: 800px) { /* styles */ }
Common Media Features
Which of the following is NOT a valid media feature for use in a CSS media query?
- device-width
- max-width
- orientation
- aspect-ratio
- text-size
Media Queries vs Responsive Images
How does a CSS media query differ from an HTML responsive image solution?
- Media queries change CSS styles; responsive images load optimized image assets.
- Media queries optimize images only for mobile devices.
- Responsive images are controlled with @media rules in CSS.
- Media queries require JavaScript to load different images.
- Media queries and responsive images are terms for the same technique.
Good Practices with Media Queries
Which practice is recommended when defining media queries for a responsive website?
- Use relative units and test on multiple real devices.
- Always use fixed pixel values for breakpoints.
- Write separate stylesheets for every possible device.
- Set breakpoints based only on device brand.
- Avoid using min-width in media queries.