Safari shows bigger font-size in landscape mode - css

In my current responsive project I have the issue that when using my iPhone in landscape mode, the font-size is a lot bigger and introducing -webkit-text-size-adjust: none; didn't help (see JSFiddle below).
I use these definitions in my project:
<meta name="viewport" content="width=device-width, user-scalable=yes"/>
and the breakpoints
#media only screen and (max-width: 35em) and (orientation:portrait) {
...
}
#media only screen and (max-width: 47em) and (orientation:landscape) {
body {
-webkit-text-size-adjust: none;
}
}
#media only screen and (max-width: 35em) and (orientation:portrait),
only screen and (max-width: 47em) and (orientation:landscape) {
...
}
You can directly test it at the result page of my JSFiddle.
<div class="test">This is just a test</div>
<div class="test">This is just a test</div>
<div class="test">This is just a test</div>
<div class="test">This is just a test</div>
<div class="test">This is just a test</div>
and
#viewport {
width: device-width;
}
#media only screen and (max-width: 47em) and (orientation:landscape) {
body {
-webkit-text-size-adjust: none;
}
}
.test {
width:100%;
margin-bottom:2px;
height:2em;
font-size:3em;
}
.test:nth-child(2n+1) {
background-color:#eeeeee;
}
What can be wrong?
UPDATE:
Even without breakpoints it doesn't work, see JSFiddle
UPDATE 2015-07-15
I found a workaround: Disable the zoom for mobile phones would solve the problem. However, as tablets get the desktop version, zoom must be enabled for tablets. I achieved a working solution now by checking the screen size in javascript and if it is below 752px I modify the viewport definition to width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0

Related

CSS rule overwritten by media queries for larger devices

I have a website where I have an element .mainContent and want it to have a different width for different devices. For smaller devices I want it to have the width of 800px and on desktop devices I want it to have the width of 1296px. Below are my CSS rules. The problem is that the last media query rule is overwriting the first rule and so the width for the desktop devices is always 800px and I don't knoq why. I did as w3school tutorial says but it doesn't work.
.mainContent {
width: 800px;
margin-right: 65px;
float: right;
}
#media only screen and (min-width: 1300px) {
.mainContent {
width: 1296px;
}
}
HTML
<div class="container-fluid">
<div class="mainContent">
...
</div>
</div>
If you not added viewport then add this viewport and it's working fine:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
If after adding viewport it's not working then Please try below code:
.mainContent {
margin-right: 65px;
float: right;
}
#media only screen and (min-width:1300px) {
.mainContent {
width: 1296px;
}
}
#media only screen and (min-width:320px) {
.mainContent {
width: 800px;
}
}
Please review this link for understand the flow of adjust media queries: ( https://www.sitepoint.com/media-queries-width-vs-device-width/ )

#media CSS in Rails

So, I'm trying to use #media in CSS on my rails project.
I have a text which needs to be displayed only on mobile Heres the code
a.html.erb
<div class="A__b--c-d">
<%= link_to .......
....
</div>
b.scss
div.A__b--c-d {
display: none;
}
#media only screen and (min-width: 200px) and (max-width: 900px){
.A__b--c-d{
display: inline-block;
}
}
I cannot seem to get the text displayed on mobile.
Heres what ive tried so far.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Pasted this in Chrome inspect element
All the names are right
You need to remove the .div and just select the max-width in your media query.
.A__b--c-d {
display: none;
}
#media only screen and (max-width: 900px){
.A__b--c-d{
display: inline-block;
}
}
You made a mistake in your media query. Try this
.A__b--c-d {
display: none;
}
#media only screen and (max-width: 900px){
.A__b--c-d{
display: inline-block;
}
}

On desktop PC, mobile css loads first, then it switches to the desktop version

So I have a website, with the responsive css (Mobile oriented). CSS stylesheet has rules for the mobile version, then (in the end of the file) #media queries start for the screens wider, then mobile.
When a page is loaded on desktop (and if this page is not cached by the browser), mobile css loades first, then in less then a second, it switches to the desktop styles. So it blinks with mobile version css (considering the fact, that desktop is wider then mobile screen, it stretches huge elements through out the page), then looks fine.
I understand, that the browser needs to load the stylesheet completely, and before it did so, it shows what it has already loaded. I understand, that this behavior is explainable, but it still bugs me.
Is there a way to load the css without blinking with mobile version (but WITHOUT making it desktop oriented (so that the desktop css loaded first, and the rest was handled by the #media queries)) and should I even bother about it (or is it just fine and should remain that way)?
Here is some code:
Meta tags before CSS:
<meta charset="UTF-8"/>
<meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
<link rel="apple-touch-icon" href="images/icn.png" />
<link rel="shortcut icon" href="images/icn.png" type="image/x-icon" />
Invoking CSS from an HTML file:
<link rel="stylesheet" href="styles/page1.css">
CSS File example (shortened (this is just an example of the structure of CSS in the file)):
html {
margin:0;
height:100%;
padding:0;
}
body {
height:100%;
margin:0;
padding:0;
font-size:16px;
}
.first-panel {
background: black;
width:250px;
height:100vh;
color:white;
position:fixed;
left:0;
clear:both;
top:0
}
.no-user-select {
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none
}
#media only screen and (min-width:480px) {
}
#media only screen and (min-width:640px) {
}
#media only screen and (min-width:768px) {
}
#media only screen and (min-width:1024px) {
.first-panel {
background: white;
color:black;
}
}
#media only screen and (min-width:1280px) {
}
Adding "max-width" to your media-selector should do the trick:
#media only screen and (min-width:480px) and (max-width: 639px) {
}
#media only screen and (min-width:640px) and (max-width: 767px) {
}
#media only screen and (min-width:768px) and (max-width: 1024px) {
}
#media only screen and (min-width:1024px) and (max-width: 1279px) {
.first-panel {
background: white;
color:black;
}
}
#media only screen and (min-width:1280px) {
}
There are few approach you can use
1st Approach by using CSS File
<link rel="stylesheet" media="screen and (min-width: 600px)" href="small.css">
<link rel="stylesheet" media="screen and (min-width: 4000px)" href="big.css">
2nd by using Javascript
if (window.matchMedia('screen and (min-width: 600px)')){
document.write('<link rel="stylesheet"
href="small.css">');
}
I suggest for better one you need use only one css file and define the concept like as below :
#media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ }
#media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ }
#media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ }
#media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
#media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
#media (min-width:1281px) { /* hi-res laptops and desktops */ }

Display Different DIVs For Mobile Devices

I have some onMouseOver functions that don't work particularly well on mobile devices. Would it be possible for me to have a different DIV displayed on mobile devices?
Here's a late response to your suggestions. Basically, I want a separate DIV (without the onMouseOver) if the display is mobile.
<!-- services -->
<section class="services" id="services">
<div class="container ptb">
<div class="row">
<h2 class="centered mb"><b>SERVICES</b></h2>
</div> <!-- Services Headline -->
<img src="assets/img/services-flip.png" height="50%" width="50%"
onMouseOver="this.src='assets/img/services-list.png'"
onMouseOut="this.src='assets/img/services-flip.png'" />
</div> <!-- Content, Image -->
</section>
<!-- end services -->
Media queries are your friend.
Example:
#media screen and (max-width: 768px) {
div.mobile { display: block; }
div.desktop { display: none; }
}
Aside from Media Queries, you can also use something like: http://detectmobilebrowsers.com/
Essentially you can include a script like this, and do something like this:
$(document).ready(function(){
if(jQuery.browser.mobile) {
$('body').addClass('mobile');
}
});
And based on the body class "mobile", hide / display the necessary divs. (this is the jQuery example, but you can do it using plain JS as well)
Sure you can .
Use css's CSS Media Queries
Here is a great reference for apple products screen sizes.
http://stephen.io/mediaqueries/#iPhone
div{
width: 100%;
height:100%;
padding: 0;
margin:0;
left:0;
left:0;
}
#desktopView{
background:rgb(50,50,80);
display:block;
}
#mobileView{
background:rgb(50,80,50);
display:none;
}
#mobileLandscapeView{
display:none;
background:rgb(80,50,50);
}
/* iPhone 6 in portrait & landscape */
#media only screen and (min-device-width : 375px) and (max-device-width : 667px){
/* where you can hide unwanted DIV and show a special MOBILE DIV if desired */
#desktopView{
background:rgb(50,50,80);
display:none;
}
#mobileView{
background:rgb(50,80,50);
display:block;
}
#mobileLandscapeView{
background:rgb(80,50,50);
display:none;
}
}
/* iPhone 6 in landscape */
#media only screen and (min-device-width : 375px) and (max-device-width : 667px) and (orientation : landscape) {
/* where you can hide unwanted DIV and show a special MOBILE DIV if desired */
#desktopView{
display:none;
}
#mobileView{
display:none;
}
#mobileLandscapeView{
display:block;
}
}
<div id="desktopView">Should see in desktop mode</div>
<div id="mobileView">Should see in iPhone 6 vertical mode</div>
<div id="mobileLandscapeView">Should see in iPhone 6 landscape mode</div>

media css3 is not working on safari browser

I am customizing bootstrap for 3>>2>>1 columns display on browser resize or small devices. I have used css3 media query which is working on all browser except Safari. Following is css i have used. It's always using the first media query and because of that it is causing issue on Safari. I have tested both Mac and Window Safari and faced same issue. Please help.
Viewport Added in HTML head section
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
CSS3 Used:
/*Apply different margin based on media size*/
#media (min-width:1632)
{
.two-column .row-fluid [class*="span"]:nth-child(3n+1)
{
margin-left:100px;
}
}
#media (min-width: 981px) and (max-width: 1631px)
{
.two-column .row-fluid [class*="span"]:nth-child(2n+1)
{
margin-left:100px;
}
}
#media (min-width: 982px) and (max-width: 1155px)
{
.two-column .row-fluid [class*="span"]:nth-child(2n+1)
{
margin-left:10px;
}
}
#media (min-width: 545px) and (max-width: 981px)
{
.two-column .row-fluid .span6
{
margin-left:5%;
}
}
#media (max-width: 546px)
{
.two-column .row-fluid .span6
{
margin-left:5px;
}
}
Bootstrap explicitly do not support Windows Safari as stated in their browser support docs.
It looks like you are missing the 'px' after #media (min-width:1632)
#media (min-width:1632px)
This should fix it.

Resources