Device orientation metadata - javascript

I have designed a website using media-query.
In the browser it is looking perfect. But when i am checking in the tablet or in mobile device, in portrait mode it is good,
but when I am changing the device orientation portrait to landscape then it is not looking perfect. So my doubt is "is there any meta-data to disable the device orientation, so even though user change the device orientation then the content will not rotate."
thanks,
naresh kumar.

If i understood you properly, you no need to disable the orientation but rather you can adjust screen elements even when the device is rotated. You can use the below queries:
#media all and (orientation: portrait) { ... }
#media all and (orientation: landscape) { ... }
Because a good design should fit in all devices and in all orientations perfectly...

Related

change css on changing resolution of desktop screen

my website looks like this on 100% resolution
this is my 100% resolution image
But, when i make resolution to 90% by pressing the combination of 'ctrl' and '-'
it is overlaping like this:
this is my 90% resolution image
how to define css for 90% resolution
Plz help me.
You also can use flexbox to avoid this sort of troubles. Very powerful thing.
Gives you full control over blocks, also responsive.
Changing css based on resolution or device type will be possible only with. MediaQueries.
Example:
#media screen
and (min-device-width: 1200px)
and (max-device-width: 1600px)
and (-webkit-min-device-pixel-ratio: 1) {
.your_desired_class{
background-color:red;
}
}
You can play with min-device-width
Find the basic in http://www.w3schools.com/css/css3_mediaqueries_ex.asp

Media Queries: How to target only tablet?

I have been doing some research on media queries and I understand the concept of mobile-first design.
I know, that there are lots of questions regarding media queries but none of them targets my specific question.
Also I understand the concept of structuring your stylesheets with media queries like this:
/* Small devices (tablets, 768px and up) */
#media (min-width: 768px) { ... }
/* Medium devices (desktops, 992px and up) */
#media (min-width: 992px) { ... }
/* Large devices (large desktops, 1200px and up) */
#media (min-width: 1200px) { ... }
However I really need a way for my stylesheets to target only tablets regardless of the browser resolution (width & height). Checking the browser-width is simply not safe enough (and definitely not what I am searching for) in 2015 where some tablets have a bigger resolution than older desktops.
Here is a list of things I have tried so far:
I made a list of "common" tablet-resolutions and simply specified
detailed media queries. This approach failed after I found tablets
with 1024px width (which is the same as older desktop browsers).
I read a lot about media queries and found out that modern browsers (especially on tablets) sometimes ignore specifications like "#media only screen" and that most values of a media query are deprecated.
1.) Is there a safe way to target tablets regardless of their resolution with media queries?
2.) Is there any way to use JavaScript/JQuery to find out if the Browser is used on a Tablet (touchscreen)?
Maybe there is a certain css property OR JavaScript function that is only "triggered" on tablets (I am out of ideas)? Thank you for your help.
You can use this:
#media only screen and (min-device-width: 768px){}
For ref : Media Queries: How to target desktop, tablet and mobile?
Short answer: no.
I would say, what is a tablet nowadays? Some phones are so big that they seem more like tablets and some tablets are so small that they overlap the bigger phones market...
So I would say, go for feature detection, target the features that you are interested in, and the best way for me, apart from media queries, is Modernizr.
You can take a look at their custom builds page and literally pick the features that you are interested in (touch events? geolocation?), knowing that you got the support of a reliable, well tested library.

Reponsive website partially based on device instead of screen resolution

I've got my responsive website done with breakpoints setted up with #media queries. I've got couple of basic breakpoints
min-width: 1600px - for TVs and bigger resolution screens (that just center the whole page and make white margins on sides, nothing too significant)
max-width: 1024px - for tablets, there are many changes, especially because tablets has of corse touch screen, which desktops usually haven't. At all it looks pretty different.
max-width: 600px - for smarphones, there is also a lot of changes based especcialy on narrowing the content from two or four colums into one.
Now I found that might be a problem, because there are nowdays tablets which acts in the browser, as they have resolution width for example 1280px, but there are also still computers with width of monitor 1280px too, even smaller, so I can't change the breakpoint value for this.
I of course don't want the desktop version on tablet and tablet version on comuter, becase they're created not as much for resolution but more for the platform.
I know that there are things called user agents like WURFL, which seems to be perfect for this. But is there any way how to connect this value from WURFL (tablet, desktop, smartpohne...) with css #media queries.
For example detect in WURFL that the device is tablet and change the breakpoint value in CSS file, so it shows the tablet version, instead of desktop version? Or is there any other way with similar result as this theoretical solution?
There is no need identify the device, just use the right media queries.
#media only screen and (min-width : 320px) {
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
}
I think you are looking for this
jQuery code to detect mobile devices
http://www.webtrainingcentre.com/jquery/scripts/jquery-code-to-detect-mobile-devices/

Scaling Mobile Responsive Landscape Layout for Portrait Display

I have a responsive web page layout designed for Mobile landscape display (480px) in mind and want to use that same mobile landscape layout for mobile Portrait display at (320px). Can anyone think of a way to scale down this view so that it display also for (320px) without adding another css media query specifically for 320px display?
Set all sizes in rems and jack up font size to 150% in landscape mode? As long as you don't use pixels, everything will scale up
http://snook.ca/archives/html_and_css/font-size-with-rem
To display mobile landscape layout same in the mobile portrait layout you have to use below media query only. So, when you rotate your mobile from landscape to portrait or vice versa, the same layout will display.
#media screen and (max-width: 480px)

Icon size using media queries

I am developing an app which runns on mobile and desktop browsers. I'm trying to find a sollution that could fix my icon size. I want icons to be small on desktop browsers but bigger on mobile browsers.
Can media queries detect screen density and if so can screen desinity determine my icon size?
And another thing: Is it better to detect screen size or density and adjust icons depending on the better choice.
Yes there is a media query that detects pixel density. Here is an example:
#media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
/* Then you would change your background image and background image size here */
}
There is also a ton more info in this article at CSS-Tricks.
The question of whether to target device size or pixel density is tricky: it will depend on the specifics each time, and there's nothing to say you shouldn't combine both in your site. The media query you want to cover everything is:
#media (min--moz-device-pixel-ratio: 1.5),
(-o-min-device-pixel-ratio: 3/2),
(-webkit-min-device-pixel-ratio: 1.5),
(min-resolution: 1.5dppx) {
/* your retina rules here */
}
...which is probably the most helpful if you're sticking with PNGs rather than SVG graphics or an icon font. I recommend looking at retinafy.me - it's a useful resource (but not free), which is where that code came from.

Categories