curriculum/challenges/english/blocks/review-responsive-web-design/671a98927af7829722697dc2.md
:::interactive_editor
<link rel="stylesheet" href="styles.css">
<p class="mq-example">The background of this paragraph will change when the viewport is at least 768px wide.</p>
.mq-example {
padding: 10px;
border: 1px solid #ccc;
background-color: lightyellow;
}
@media screen and (min-width: 768px) {
/* Styles for screens at least 768px wide */
.mq-example {
background-color: lightblue;
}
}
:::
all Media Type: This is suitable for all devices. This is the default if no media type is specified.print Media Types: This is intended for paged material and documents viewed on a screen in print preview mode.screen Media Types: This is intended primarily for screens.aspect-ratio: This describes the ratio between the width and height of the viewport.@media screen and (aspect-ratio: 16/9) {
/* Styles for screens with a 16:9 aspect ratio */
}
orientation: This is used to indicate whether the device is in landscape or portrait orientation.:::interactive_editor
<link rel="stylesheet" href="styles.css">
<p class="orientation-example">This paragraph's background will change in landscape orientation.</p>
.orientation-example {
padding: 10px;
border: 1px solid #ccc;
background-color: lightyellow;
}
@media screen and (orientation: landscape) {
/* Styles for landscape orientation */
.orientation-example {
background-color: lightgreen;
}
}
:::
resolution: This is used to describe the resolution of the output device in dots per inch (dpi) or dots per centimeter (dpcm).@media screen and (min-resolution: 300dpi) {
/* Styles for high-resolution screens */
}
hover: This is used to test whether the primary input mechanism can hover over elements.:::interactive_editor
<link rel="stylesheet" href="styles.css">
<button>Hover over me</button>
button {
padding: 10px 20px;
font-size: 1rem;
background-color: lightgray;
border: 1px solid #999;
cursor: pointer;
}
@media (hover: hover) {
/* Styles for devices that support hover */
button:hover {
background-color: yellow;
}
}
:::
prefers-color-scheme: This is used to detect if the user has requested a light or dark color theme.and operator is used to combine multiple media features, while not and only can be used to negate or isolate media queries.:::interactive_editor
<link rel="stylesheet" href="styles.css">
<p class="logical-example">This paragraph's background will change when the screen is at least 768px wide AND in landscape orientation.</p>
.logical-example {
padding: 10px;
border: 1px solid #ccc;
background-color: lightyellow;
}
@media screen and (min-width: 768px) and (orientation: landscape) {
/* Styles for landscape screens at least 768px wide */
.logical-example {
background-color: lightcoral;
}
}
:::
:::interactive_editor
<link rel="stylesheet" href="styles.css">
<p class="breakpoint-example">This text will change size when the viewport width is at least 768px.</p>
.breakpoint-example {
font-size: 1rem;
padding: 10px;
border: 1px solid #ccc;
}
/* Styles for screens wider than 768px */
@media screen and (min-width: 768px) {
.breakpoint-example {
font-size: 1.125rem;
background-color: lightblue;
}
}
:::
:::interactive_editor
<link rel="stylesheet" href="styles.css">
<div class="container">
<p>The width of this container changes based on the viewport size.</p>
</div>
/* Base styles for mobile */
.container {
width: 100%;
padding: 10px;
background-color: lightblue;
}
/* Styles for larger screens */
@media screen and (min-width: 768px) {
.container {
width: 750px;
margin: 0 auto;
padding: 20px;
}
}
@media screen and (min-width: 1024px) {
.container {
width: 960px;
}
}
:::
Review the Responsive Web Design topics and concepts.