Responsive theme patterns help your website look good on all devices, like phones, tablets, and computers. They make sure your site adjusts its layout and style automatically.
Responsive theme patterns in Wordpress
/* Example CSS for responsive theme pattern using media queries */ @media (max-width: 768px) { body { font-size: 1rem; padding: 1rem; } .sidebar { display: none; } } @media (min-width: 769px) { body { font-size: 1.2rem; padding: 2rem; } .sidebar { display: block; } }
@media queries in CSS to apply different styles based on screen size./* Hide navigation menu on small screens */ @media (max-width: 600px) { nav { display: none; } }
/* Stack columns vertically on small devices */ @media (max-width: 768px) { .content, .sidebar { width: 100%; float: none; } }
/* Increase font size on larger screens */ @media (min-width: 1024px) { body { font-size: 1.25rem; } }
This WordPress template shows a simple responsive layout. On wide screens, content and sidebar sit side by side. On small screens, the sidebar disappears and content fills the width.
<?php /* Template Name: Responsive Example */ get_header(); ?> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 2rem; } .container { display: flex; gap: 1rem; } .content { flex: 3; background-color: #f0f0f0; padding: 1rem; } .sidebar { flex: 1; background-color: #d0d0d0; padding: 1rem; } @media (max-width: 768px) { .container { flex-direction: column; } .sidebar { display: none; } } </style> <div class="container"> <main class="content"> <h1>Welcome to My Responsive Theme</h1> <p>This content area adjusts based on your screen size.</p> </main> <aside class="sidebar"> <h2>Sidebar</h2> <p>This sidebar hides on small screens.</p> </aside> </div> <?php get_footer(); ?>
Always test your theme on different devices or use browser DevTools to simulate screen sizes.
Use flexible units like rem and percentages instead of fixed pixels for better scaling.
Combine responsive CSS with semantic HTML for accessibility and SEO benefits.
Responsive theme patterns make your WordPress site look good on all devices.
Use CSS media queries to change layout and styles based on screen size.
Test your theme often on phones, tablets, and desktops for best results.
Practice
Solution
Step 1: Understand responsive design goal
Responsive themes adjust layout and style to fit different screen sizes like phones, tablets, and desktops.Step 2: Identify the correct purpose
The main goal is to ensure the website looks good and works well on all devices, not just desktops or adding plugins.Final Answer:
To make the website look good on all device sizes -> Option BQuick Check:
Responsive design = look good on all devices [OK]
- Thinking responsive only speeds up desktop loading
- Confusing responsive with adding plugins
- Assuming it changes website language automatically
Solution
Step 1: Understand max-width media query
The max-width condition applies styles when the screen width is less than or equal to the given value.Step 2: Identify correct syntax
@media screen and (max-width: 600px) { /* styles here */ } uses max-width: 600px, which targets screens 600px wide or smaller. Other options either use min-width, height, or incorrect syntax.Final Answer:
@media screen and (max-width: 600px) { /* styles here */ } -> Option CQuick Check:
max-width 600px = styles for small screens [OK]
- Using min-width instead of max-width for small screens
- Confusing width with height in media queries
- Omitting 'screen' keyword or using wrong syntax
@media (max-width: 768px) { body { background-color: lightblue; } }What will happen when you view the site on a tablet with 700px width?
Solution
Step 1: Check screen width against max-width
The media query applies styles when screen width is 768px or less. 700px is less than 768px, so styles apply.Step 2: Determine effect on background color
The body background color changes to lightblue on screens 768px wide or smaller, including the 700px tablet.Final Answer:
The background color will be lightblue -> Option AQuick Check:
700px <= 768px means styles apply [OK]
- Thinking styles apply only on desktop
- Assuming CSS causes errors on media queries
- Ignoring the max-width condition logic
@media screen and (max-width 600px) { .menu { display: none; } }Why is the menu still visible on small screens?
Solution
Step 1: Check media query syntax
The media query is missing a colon ':' after max-width, which is required for valid syntax.Step 2: Understand effect of syntax error
Because of the missing colon, the media query is ignored, so the .menu styles inside it do not apply.Final Answer:
Missing colon ':' after max-width in media query -> Option AQuick Check:
Correct media query syntax requires ':' [OK]
- Forgetting colon after max-width
- Assuming display:none is invalid
- Thinking WordPress disables media queries
Solution
Step 1: Define layout for wide screens
Use min-width: 901px media query to apply two-column grid layout for screens wider than 900px.Step 2: Define layout for smaller screens
Use max-width: 900px media query to apply single column block layout for smaller screens.Step 3: Verify option correctness
@media (min-width: 901px) { .container { display: grid; grid-template-columns: 1fr 1fr; } } @media (max-width: 900px) { .container { display: block; } } correctly sets two-column grid for wide screens and single column for smaller. @media (max-width: 900px) { .container { display: grid; grid-template-columns: 1fr 1fr; } } @media (min-width: 901px) { .container { display: block; } } reverses conditions. The other options do not use media queries.Final Answer:
@media (min-width: 901px) { .container { display: grid; grid-template-columns: 1fr 1fr; } } @media (max-width: 900px) { .container { display: block; } } -> Option DQuick Check:
min-width for wide, max-width for small screens [OK]
- Reversing min-width and max-width conditions
- Not using media queries for responsive layout
- Applying same layout for all screen sizes
Ready to prove it?
Pass the test and this pattern moves unknown
