@media print {
nav, .no-print {
display: none;
}
body {
color: black;
background: white;
}
}Print media queries help remove unnecessary interface controls and improve printed readability.
Practice Exercise
Create a responsive navigation bar, a print stylesheet and a reduced-motion alternative. Test the rules using browser DevTools.
Quiz — 10 MCQs
- What does @media do? (A) Applies conditional styles (B) Creates HTML tags (C) Defines a database (D) Imports JavaScript. Answer: A. It applies CSS under matching media conditions.
- What does min-width: 768px mean? (A) Viewport width is at least 768 CSS pixels (B) Element height is 768px (C) Font size is 768px (D) Width is always fixed. Answer: A. It tests the viewport width threshold.
- How should breakpoints usually be chosen? (A) Based on where the layout needs adjustment (B) Only from device brand names (C) Randomly (D) Always at one universal value. Answer: A. Content-driven breakpoints avoid unnecessary device-specific assumptions.
- Which feature checks whether hover is available? (A) hover (B) pointer-color (C) font-hover (D) grid-hover. Answer: A. The hover media feature describes hover capability.
- What does pointer: coarse commonly indicate? (A) A less precise primary pointing mechanism (B) A large font (C) A fixed width (D) An image filter. Answer: A. Coarse pointer input is common on touch devices.
- What does @supports test? (A) Support for a CSS declaration or feature condition (B) User password validity (C) Server uptime (D) HTML title length. Answer: A. Feature queries conditionally apply styles based on support.
- Which query respects a user's reduced-motion preference? (A) prefers-reduced-motion (B) prefers-blue (C) hover: reduce (D) screen-size: slow. Answer: A. It exposes the reduced-motion preference.
- Which media type is useful for printed pages? (A) print (B) database (C) audio-only (D) source. Answer: A. Print styles can simplify printed documents.
- Does orientation: landscape guarantee a physical device is held horizontally? (A) Yes (B) No (C) Only on phones (D) Only with JavaScript. Answer: B. It describes the viewport's aspect orientation.
- Can a website use multiple media queries? (A) Yes (B) No (C) Only one per file (D) Only with Grid. Answer: A. Multiple queries can target different conditions.
Key Takeaways
- Media queries adapt styling to viewport and input conditions.
- Choose breakpoints based on content, not specific device models.
- Use feature queries, print styles and reduced-motion preferences appropriately.