Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsive CSS with high-res smart phones and tablets

I am having a issue when I try to make a web app responsive to screen-size.

I have css that I want to use for smartphones (iPhone, Andriod, blackberry, windows phone), and also have CSS I want to use for tablets.

My test devices are an iPad 3 (768 x 1024) and blackberry 10 (768 x 1280). and the widths being the same is an issue because my css starts with:

@media screen and (max-width:768px){
    //enter code here`code here
}

Because the blackberry has slightly better resolution, it renders the CSS I don't want to use for it. Is there another way I'm suppose to check the media type? I was wondering if there is a way to check the width with a measurable distance (cm or in). not sure how to solve this.

thanks in advance

like image 651
user10319 Avatar asked Feb 17 '23 19:02

user10319


2 Answers

The “pixels” that are used in CSS declarations and when the browser reports the screen size of the client device have nothing to do with the actual real-world pixels on a device's screen. The “pixels” that are used in CSS are essentially an abstract construct created specifically for us web developers. To concern your self with the actual amount of real-world pixels on a high-resolution mobile screen is, for most web applications, completely unnecessary and will only lead you to utter madness.

You can determine the browser and device type by inspecting the navigator.userAgent property in JavaScript. For example, to test for (practically) any mobile device:

 // if mobile === true, 99% chance the device is mobile.
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));

You can of course inspect navigator.userAgent to determine if the user is on a specific type of device or browser that you are particularly concerned about or having a problem with.

But again, in my personal experience, clever, simple, and flexible responsive CSS design (supported by media queries and JavaScript, too, of course) will render beautifully on 99% of device/browser combinations without having to resort to inspecting navigator.userAgent to create different styles for individual devices.

like image 84
orb Avatar answered Feb 19 '23 10:02

orb


You can also restrict your styles to the height:

@media screen and (max-width:768px) and (max-height:1024px){
    // iPAD
}
like image 31
Linus Caldwell Avatar answered Feb 19 '23 08:02

Linus Caldwell