CSS: CSS Responsive Layout

Last updated: 2026-10-13

Properties in this section: min-width

1. Responsive Images

(1) Basic Responsive Image

CSS
img {
  max-width: 100%;
  height: auto;
}

(2) Responsive Background Image

CSS
.banner {
  background-image: url("desktop-bg.jpg");
  background-size: cover;
  background-position: center;
}

@media (max-width: 768px) {
  .banner {
    background-image: url("mobile-bg.jpg");
  }
}

2. Responsive Tables

Tables can overflow on small screens. Use overflow-x: auto for horizontal scrolling:

▶ Example

▶ Try it Yourself

3. Show/Hide Elements

Use media queries to show/hide elements at different breakpoints:

▶ Example

▶ Try it Yourself

▶ Example

Responsive Flexbox grid that adapts columns to screen size:

▶ Try it Yourself

4. Testing Responsive Layouts

  1. Browser resize: Drag browser window edges
  2. Chrome DevTools: F12 → Toggle device toolbar (Ctrl+Shift+M)
  3. Real devices: Test on actual phones/tablets when possible

Properties in this section: min-width

❓ FAQ

Q How to make images responsive?
A Basic: img { max-width: 100%; height: auto; } ensures images don't overflow. Advanced: use <picture> and <source> to load different resolutions at different screen sizes. Basic version is sufficient for most cases.
Q Must responsive design have three versions?
A No. Ensure mobile experience first, then enhance on larger screens. Many pages only need mobile + desktop versions; tablet is often a natural transition. Key is "content first, device adaptation" — not responsive for responsive's sake.
Q How to test responsive effects?
A Browser DevTools can simulate various device sizes, but testing on real devices is recommended. Touch interactions feel different from simulation. Online tools like responsinator.com can also help quick preview.

📖 Summary

📝 Exercises

  1. Create a "responsive personal blog" page with header navigation, article list, sidebar recommendations, and footer copyright. Requirements: mobile single column, tablet two columns, desktop three columns + fixed sidebar.
  2. Use min-width breakpoints to change a card grid from 1 column to 4 columns, observing at each breakpoint.
  3. Create a responsive table page where tables can scroll horizontally on small screens (using overflow-x: auto).
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏