Distinguishing Between Mobile Devices and Desktop with Media Queries

With the increasing variety of devices available, identifying whether a user is using a phone or a desktop based on media queries has become more challenging. The differences in resolution, aspect ratios, and other factors between high-end phones, laptops, and low-end phones can often overlap.

If I want to create separate style sheets for phones and desktops, is there a specific media query that would work best, or should I consider a different approach like using JavaScript?

The landscape and portrait orientation method may not be effective when the soft keyboard is activated and the phone switches to landscape view.

The examples provided below are no longer reliable on all devices as they have become outdated:

@media only screen and (orientation : portrait)
@media only screen and (max-device-width: 480px)
@media only screen and (min-aspect-ratio: 13/9)

Answer №1

In my experience, sticking to the breakpoints set by Bootstrap V4, even if not using Bootstrap itself, has been beneficial. The range provided is ideal for development, particularly when implementing specific styles for larger breakpoints while following a mobile-first approach.

When considering only two breakpoints, I recommend <768px and>768px. However, opinions may vary on this suggestion as different individuals might have differing perspectives. It's important to keep in mind potential edge cases with certain devices.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determining whether an element possesses an attribute labeled "name" that commences with a specific term, apart from the attribute "value"

I'm planning to use distinctive data attributes with a prefix like "data-mo-". Let's say I have the following elements: <span data-mo-top-fade-duration="600">Title 1</span> <span data-mo-bottom-fade-duration="600">Title 2</ ...

Adjust the width of columns using HTML and CSS

UPDATED: Here is a real-life scenario I am facing: I am trying to adjust the width of columns in my table using inline CSS. Let me provide you with an example: The Table was initially set to 100%, like this: <table width=100% ...> The total number ...

Can you provide me with information on how to indicate the activated menu item by highlighting the triggering button in Angular 14 and Material Design?

Is there a way to highlight the triggering button in an Angular Material menu, while also highlighting a menu item that matches a routerLink? <button mat-button [matMenuTriggerFor]="animals">Animal index</button> <mat-menu #animals ...

What's the best way to apply a margin top to an image using Tailwind CSS?

Is there a way to adjust the top margin of an image in Tailwind CSS? I'm having trouble making my logo clearly visible and think giving it some space at the top might help. How can I do this within the Tailwind CSS framework? https://i.sstatic.net/Ae ...

Responsive Iframe设计

My website has an issue with making the iframe responsive. The map displays correctly on a computer, but is invisible on mobile phones. I am currently using Bootstrap for the layout. <div class="container d-none d-sm-block mb-5 pb-4"> <d ...

How can CSS be used to prevent line breaks between elements in a web page?

div#banner>img { float: left; background-color: #4b634b; height: 265px; width: 80%; } ul { float: left; background-color: #769976; width: 162px; } <body> <div id="wrapper"> <header> <nav> <ul ...

PHP Retrieve Current Time with AM/PM Display

Can anyone help me figure out how to use PHP to get the current time along with AM/PM indication? The code I have doesn't seem to be working correctly. Here is the code snippet that I am currently using: $format1 = date("G"); // this should give the ...

Show child element when hovering over parent element

My current issue involves a button animation I am attempting to create. I envision a description box smoothly sliding out from behind a button whenever it is hovered over. However, my current implementation lacks the desired transition effect and simply ju ...

Tips for aligning vertical text perfectly

After spending the entire day researching vertical text, I am still struggling to find a simple solution. I need three items in my header to line up horizontally: an image on the left, a specific-sized box in the center, and another image on the right. Her ...

What is the best way to eliminate the border around the input beneath the li element

I am trying to create a language tab input like this: https://i.sstatic.net/N0h2o.png But I want it to look like this: https://i.sstatic.net/QmnSr.png However, I am facing an issue with the border when any language tab is active! Here is my code in En ...

What is the best way to customize arrow designs in a React Slick Slider?

I am struggling to customize the arrows in react-slick with my own PNG images. Despite my efforts, the images appear distorted on the screen as they are automatically set to a width and height of 20px instead of their actual size of 17x27px. I have experim ...

What is the best way to conceal a Material UI button with CSS?

For my TODO react app, I am using a Material UI button. My goal is to create a form with an input field and a submit button, but I want the submit button to be invisible so that users think the form submits when they press the "Return" key. import { Tex ...

Align the inner container in the outer container-fluid

I'm struggling to center a container inside a container-fluid. Any suggestions on how to make it work? /* Setup Buttons Specific Styling */ .setup-bg { background: url("https://image.ibb.co/geAGqy/setupbtns_bg.png"); background-repeat: no-repea ...

What causes my elements to move to the left when the screen size decreases with bootstrap?

If you want a better understanding of the situation, looking at images might be helpful. Here is how it typically appears: https://i.sstatic.net/mBZDp.jpg And this is how it appears on smaller screens: https://i.sstatic.net/8CuIs.jpg For smaller scree ...

Unable to Retrieve Images from Different Directories using Rails Image_Tag

After three days of troubleshooting, I can't help but wonder if there are some specific rules regarding the image_tag function in a Rails environment. The code snippet in my application.html.erb file within the layout directory is as follows. Let&apos ...

Can the arrangement of icons/buttons on the JW Player control bar be customized?

I am trying to customize the skin of my JWplayer like this: This is my current progress: I have been researching how to rearrange the order of icon / button on the controlbar. According to the jwplayer documentation, the buttons on the controlbar are div ...

Balanced row heights within a CSS grid

Using a basic grid framework like , I have a fixed number of rows. I'm wondering if there's a simple way to ensure that all rows have the same height without explicitly setting the height of the .row class as a percentage. This is how my row cla ...

Issues with the z-index in a dropdown menu

Hey, need a little assistance here. I'm facing an issue with my drop down menu. It seems to always be one layer behind the body, even though I've set the z-index of the menu to 999 and the z-index of the body to -999. Could you please take a loo ...

Loading JSON and HTML div in the correct order: Reloading vs Refreshing

Currently, I am working on developing a code snippet to retrieve and showcase stock data for my Smart Mirror Project. Although the script successfully displays all of the necessary information, I am encountering difficulties when attempting to update the s ...

Issue: Invalid element type detected: expected a string (for built-in components) or a class/function

Currently, I am in the process of learning how to make API calls using React Redux. I decided to practice by implementing an example in StackBlitz. However, I encountered an error after selecting a channel and clicking on the 'Top News' button. C ...