Repository navigation
WEB DEVLOPEMENT #1902
Replies: 3 comments
|
Media queries are definitely an important part of responsive design, but I wouldn't rely on them alone. A good modern approach is to build the layout mobile-first and combine several techniques:
For example, instead of creating separate desktop and mobile versions of a page, I usually start with the mobile layout and progressively enhance it: .container {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
}
@media (min-width: 768px) {
.container {
grid-template-columns: repeat(2, 1fr);
}
}So I would say media queries are still essential, but the bigger idea is to create fluid and flexible layouts that naturally adapt, and then use media/container queries when a specific layout change is actually needed. For someone learning responsive design, I'd focus first on Flexbox → Grid → mobile-first design → media queries → fluid sizing → container queries. |
|
To make the flexible-layout advice above concrete, try this small experiment: let the available space decide how many cards fit, without adding a media query. Include the usual viewport setting in your HTML head: <meta name="viewport" content="width=device-width, initial-scale=1">Then use this markup: <main>
<h1>Three practice cards</h1>
<div class="cards">
<article><h2>One</h2><p>Some short text.</p></article>
<article><h2>Two</h2><p>Try a much longer sentence here and watch the row grow taller.</p></article>
<article><h2>Three</h2><p>TryAnUnbrokenStringToCheckWrappingWithoutHidingTheContent.</p></article>
</div>
</main>* { box-sizing: border-box; }
body { margin: 0; font: 1rem/1.5 system-ui, sans-serif; }
main { max-width: 64rem; margin-inline: auto; padding: 1rem; }
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
gap: 1rem;
}
.cards > article {
min-width: 0;
overflow-wrap: anywhere;
padding: 1rem;
border: 1px solid;
}
Resize the window, then increase the root font size. Compare with Media queries are still useful when you want a deliberate change in layout at a viewport breakpoint. First make the content flexible; add a breakpoint when the content needs that change, rather than one for each named device. References: MDN's auto-placement example and CSS min(). Disclosure: AI-generated and browser-checked by PagePatch's Codex assistant. PagePatch sells HTML/CSS templates; this reply has no product link. Independent of Microsoft and its curriculum. |
|
Yes! Let's understand responsive web design with a simple HTML and CSS example. The best approach is Mobile-First Design. This means designing for mobile screens first and then adjusting the layout for tablets and desktops. 1. HTML Code
2. CSS Code
3. How does it work?Mobile View Below 768px
Desktop View 768px and above
4. Important techniques to learn
My recommendation: Learn these techniques in this order: Flexbox → Grid → Media Queries → Mobile-First Design → Responsive Images. This will give you a strong foundation for building modern responsive websites. The best approach is Mobile-First Design. This means designing for mobile screens first and then adjusting the layout for tablets and desktops. 1. HTML Code2. CSS Code3. How does it work?Mobile View Below 768px [How to Create a Responsive Website Header - Part 2 - Web Development Tutorial by Christopher Spicer | CBSpicer Art](https://images.openai.com/static-rsc-4/RftFIW7pVL6sKqta7TFfLQtg4L-8M4A4sbTryIYTtgmoG73mXiHQy93yHRQjHilw8Sl9WT7ubHJIuiR33VCV_YB9WVsy9zBNkOAZgKa4ImExi1CTInB28759BnjuC8fGXLiTM7nfASyFglfgC7OhEYQMsrO0TpQHwdfWglZcYoU?purpose=inline) [cbspicer.com](https://www.cbspicer.com/blog/web/how-to-create-a-responsive-website-header-2.htm?utm_source=chatgpt.com)
Desktop View 768px and above [Premium Responsive Header - HTML, CSS & JS Code | Modern Navbar Design](https://images.openai.com/static-rsc-4/m3MbJMysmvPfJxp6G6DDHXPa-nvWMUTMSyJH-JPK4xBHD2y4nr_kU0J3C9qeItNuHke3KMff8VxBxgTI6BuwjPuQFKAi4_0EOOGfA5KhYawUwSTn_c3BMEswxzVO6VaMlJpjonAJIuDCa7qM0DbLywtHjS5KIfVL2-jB4qpP7ew?purpose=inline) [codepen.io](https://codepen.io/Kuldeep-Rajput-the-sasster/details/yyYzXWG?utm_source=chatgpt.com)
4. Important techniques to learn
My recommendation: Learn these techniques in this order: Flexbox → Grid → Media Queries → Mobile-First Design → Responsive Images. This will give you a strong foundation for building modern responsive websites. |
Uh oh!
There was an error while loading. Please reload this page.
'm learning web development and I'm trying to understand responsive design better. What is the recommended approach for building a responsive website today? Should I rely mainly on CSS media queries, or are there other techniques I should learn as well?
All reactions