Media Queries: How to target desktop, tablet, and mobile?

Cover Image for Media Queries: How to target desktop, tablet, and mobile?
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

Media Queries: How to target desktop, tablet, and mobile? 📱💻🖥

Are you feeling lost when it comes to targeting different devices with media queries? Don't worry, we've got you covered! In this blog post, we'll walk you through the common issues, provide easy solutions, and give you a generic system to target desktop, tablet, and mobile. Let's dive in! 💦

Understanding the problem 🤔

Media queries allow us to apply different styles based on the characteristics of the device our website is being viewed on. However, finding the right breakpoints for each device can be a daunting task. Let's break it down:

  • 💻 Desktop: These are typically larger screens with a wider width. We can target desktop with a min-width media query, such as only screen and (min-width: 992px). This ensures that the styles are applied only when the screen width is equal to or greater than 992 pixels.

  • 📱 Mobile: These are smaller screens with limited width. For mobile, we can use a max-width media query to target screens up to a certain width. For example, only screen and (max-width: 480px) will apply styles when the screen width is less than or equal to 480 pixels.

  • 📲 Tablet: Tablets fall somewhere between mobile and desktop. To target tablets, we can set specific breakpoints that cover the range of tablet screen sizes. For instance, only screen and (min-width: 768px) and (max-width: 991px) will apply styles to screens with widths between 768 and 991 pixels.

Generic system for targeting devices 🎯

While the examples you found are a good starting point, let's refine them into a more generic system that you can use to target devices in a consistent manner:

/* Mobile */
only screen and (max-width: 767px)

/* Tablet */
only screen and (min-width: 768px) and (max-width: 991px)

/* Desktop */
only screen and (min-width: 992px)

In this system, the mobile breakpoint covers screens up to 767 pixels wide. The tablet breakpoint includes screens with widths starting from 768 pixels up to 991 pixels. Finally, the desktop breakpoint targets screens with widths equal to or greater than 992 pixels.

Call-to-action: Share your experience! 📢

We hope this guide has simplified the process of targeting desktop, tablet, and mobile devices with media queries. Now it's your turn! Have you encountered any challenges while applying media queries? Do you have any tips or tricks to share? We'd love to hear from you in the comments below. Let's help each other create responsive and user-friendly websites! 🙌

So go ahead, drop a comment and let's start a conversation! 🗣️


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my

Matheus Mello
Matheus Mello