Bootstrap - Modify Media Queries - ruby-on-rails

I'm using twitter-bootstrap 2.2.8 and rails 4.
Where applicable, I've set up different divs for desktop, tablet and phone using the following classes:
.visible-desktop, .visible-tablet, .visible-phone
The problem is that, with the way bootstraps media queries work, the iPad(landscape) is using the desktop code not the tablet version which is a major problem.
Is there any way to modify bootstraps media queries so that the tablet max-width is, for example, 1024px instead of the current value (979px)?

If you don't mind hacking at the Bootstrap CSS you just need to find the Media Queries and change them to whatever width/height you want. You'll find lines like this
#media (min-width: 768px) { /*some css*/}
Just change these values to whatever you want (the media queries will appear in many different places throughout the css) and that will change the various classes, so in your case there should be something like
#media (max-width: 979px) {
.visible-tablet{
display:block;
}
}
Just change that media query to 1024 and your away. Just be mindful of messing with the media queries too much, as certain classes with widths (such as the various span* classes) might start behaving weird once you start messing with the points at which the media queries change.

Related

Safari on mobile - computed style is different than given

I am writing an Angular (v.9) web application which contains few tiles on the scrolling panel. When given option is out of order I set blurred grey background with text on it. It works fine on desktop chrome/firefox/edge and mobile chrome/firefox. However when I test it on iOS with Safari text becomes too large for the tile. Even though I set font-size property on the "p" element itself:
<p style="font-size: 14px">
sometimes computed style says 21px.
As you can see, I marked that with red rectangles. Moreover, the issue does not appear on all tiles - as you can see blue one looks fine - font size is 14px. Unfortunately the presence of the issue on the particular tile seems to be totally random.
I use BrowserStack for testing, problem appears only on all iPhones (checked 8, 10, 11, 12) with Safari. Running Chrome does not produce issue.
It is not possible to expand "font-size" tree so I have no idea where that value come from, I haven't set 21px anywhere.
Do you have any ideas how can I force Safari to use given font-size? I've already tried multiple tricks like using !important, changing size based on some properties or even set different font size on click - works on all browsers but Safari.
Try this (only for iPhones)
#media screen and (max-device-width: 480px){
body{
-webkit-text-size-adjust: none;
}
}
and also make sure your code has the correct device meta tag
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
This is the mixin that I use for the Safari browsers
#mixin safari-only {
#supports (-webkit-marquee-repetition: infinite) and (object-fit: fill) {
#content;
}
}
You can use that in your .scss file as follows:
#include safari-only() {
// your CSS
}

Why font-size in iPhone mail so tiny? Had to scale up to 26px

I'm working on a responsive email template for my employer. For the desktop size, I was able to leave the default font size at 16px and just use rem to adjust sizes as necessary. It looks fine on the desktop, in Gmail, and is fully responsive. However, when viewed in Mail on iPhone, the font is SO SMALL. I had to add a media query that increases the base font size to 26px to get reasonable font sizes in the email. I've tried doing some research, but it doesn't seem as if other people have had to do the same. There is very little CSS in the code, but here is what I have:
body, table, td, a, p, span {-webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%;}
#media screen and (max-width: 600px) {
html, td {
font-size: 26px !important;
line-height: 1.3;
}
}
I also have
<meta name="viewport" content="width=device-width, initial-scale=1">
There is some other CSS having to do with resizing images, with margins, etc. but that is the only CSS dealing with font-sizes (all the rem info is inline so it isn't stripped out by Bronto/Gmail). If I resize it in the browser to a mobile size, the text looks massive, but when viewed on my iPhone, it looks great. I'm concerned that this may be an iPhone quirk though and that it will look massive on other types of devices. Does anyone have any insight?
Here is some code from the templates I use (where I don't see this issue):
Try making your <meta> tags look more like this:
<meta name="x-apple-disable-message-reformatting">
<meta name="viewport" content="width=device-width">
The first tag disables auto-scale in iOS 10 Mail, which could be affecting your text size. The second tag sets the viewport; forcing initial-scale shouldn't be necessary and could be throwing off your design.
Also try moving the inline body styles from the <body> tag to inside a universal selector in <style>, like so:
<style>
/* What it does: Stops email clients resizing small text. */
* {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
</style>
<body width="100%" bgcolor="#ffffff" style="margin: 0; mso-line-height-rule: exactly;">
Have you heard of the viewport meta tag? You should consider adding this tag to the meta on your site. Just be cautious though as it could manipulate other HTML elements you have already configured.
<meta name="viewport" content="width=device-width, initial-scale=1">
Here is a link to a page explaining what it does in further detail.
https://developer.mozilla.org/en/docs/Mozilla/Mobile/Viewport_meta_tag
Okay, finally figured it out. Luckily I had been going through and making all our email templates responsive, and one of them didn't have a hero image. Guess what? The font size looked massive on mobile for the imageless-template! So after some experimentation, I found that
img {
width: 100% !important;
}
completely resolved the issue, so that now the actual font-size matches what is set in the CSS. Despite all the width:100% styles set on the image itself and on its parent containers, somehow the image must have been too large and triggered a resize of all content, I guess? If anyone has an explanation I'd love to hear it.
FWIW, I think you are complicating your life trying to use the text-size-adjust property.
According to the browser compatibility chart on this MDN document, there is poor browser support and it's buggy.
Secondly, the way I read this W3C doc I don't think you are using it for its intended purpose. W3C states that:
This module contains features of CSS relating to one possible
mechanism for adapting pages designed for desktop computer displays
for display on smaller screens such as those of mobile phones...
Its purpose is to provide a solution for pages which were designed for desktop display only.
As you know, older web pages which don't use the viewport meta tag will be scaled down to fit the viewport of a mobile device. The problem with this is that text often becomes too small to read and this text-size-adjust property proposes to remedy this by enlarging text on mobile devices.
I think if you continue to use the viewport meta tag, make your template responsive, and size elements so that they display well in all devices you would get good results if you don't use text-size-adjust, i.e. some like the following:
body, table, td, a, p, span {font-size:16px;}
Good sources of info about text-size-adjust:
https://developer.mozilla.org/en-US/docs/Web/CSS/text-size-adjust?v=control
https://drafts.csswg.org/css-size-adjust/#text-size-adjust
https://caniuse.com/#search=font-size-adjust

postion:fixed, iphone, and media query

I am having some trouble with this and haven't found a solution.
The solutions I find are for background-size:cover; when applying to a whole page, whereas I am using this on a specific div.
First, the site is http://www.sexypizzamarketing.com.
If you check this site, there is a DIV with a background-size:cover for an image, and here is the css:
#div3 {
margin-top:40px;
background-image:url("images/Desert.jpg");
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:100%;
background-repeat:no-repeat;
background-attachment:fixed;
background-color:#914211;
color:#201E1E;
background-color:#A4FFEE;
height:600px;
}
so as you scroll down, this 600px div moves over a fixed image. all of the research I've done is talking about how this background-position:fixed does not work on mobile. but when ive tested this on my android phone and a windows phone (and all browsers on PC) this has worked.
so really, unless you have an iphone, you won't be able to see this problem. ive used testmobile.me to test iphone, and it does not show up there. This is driving me crazy, because until now, I've been editing the live site, then asking someone to screenshot the site and send it to me... yea. 1. does any one know how to solve this?
So next, I decided to scrap this on iphones, would get rid of it for iphones. so I included this in css,
#media only screen and (max-width: 700px), only screen and (max-device-width: 700px) {
/* CSS overrides for mobile here */
#div3 {
background-color:black;
height:500px;
background-image:url("images/Background.jpg");
}
and this isn't hasn't solved it either.
**EDIT. this makes sense, but I didnt realize it. I put the #media only css to specify device width for a specific div (div3) above the regular div3 css, so it wasn't overriding. I moved it to the bottom of the section, allowing the #media to override the div3 css, so this solved that. A few things- this targets all media devices max width:700px, not just iphones. so i will look into that (because the site worked fine on windows and android phone)
As soon as I get the spare iphone and figure out how to connect it to localhost, then I will try the suggestions from alexander, because I don't want to risk messing something up by editing the live site through cpanel.
I'll be getting an old iphone for testing purposes as well.
but any suggestions, or if you can point me in the right direction, I'll make you some shrimp tacos or something.

Understanding how bootstrap works in a Ruby on Rails (4) application

I have an existing Ruby on Rails 4 application and I have set up bootstrap within. The buttons, forms and other small things I've utilised have been great!
Now I am absolutely perplexed when it comes to bootstrap and responsive design. From what I've read, embedding bootstrap into your app should be responsive out of the box, but this doesn't seem to be the case (or maybe I'm doing it wrong).
In my application.html.erb head tag I have:
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
I've looked at this section on the bootstrap site, but I don't see how adding hidden/visible classes is going to help my case, especially when header/footer widths need to change when the browser gets smaller.
I've been doing stuff like this so far:
#media only screen and (min-width : 175px) and (max-width : 400px) {
/* styles here for 175px to 400px */
}
So what I've been doing is setting up my own media queries. Now my question is: IS setting up media queries necessary when using the bootstrap framework? I've had some OK success so far using my own queries, but it's very, very tedious: everything on my site looks pretty good when the browser is large, but when it gets small, everything goes to shit.
If anyone could offer some insight on this, it would be much appreciated. I feel like I'm making responsive design much harder than it ought to be.
Integrate bootstrap into your app does not mean your website become responsive. It depends on the elements and classes that you are using on your site. If you have lots of custom CSS classes then you will need to define your own #media query.
In this case, I think you should take a deeper look into your app to see if you are really using Bootstrap classes in all places. If you see strange behaviors on mobile devices, then it should be because of your custom CSS classes
If you look into bootstraps documentation, bootstrap 3 has a lot of css features which will help you to make your app responsive.
Grid System:
Bootstrap 3 provides you grid classes according to your device like: col-md-1(for medium size desktop), col-sm-1(for your tablet) ,col-xs-1(for your mobile) so if you want to resize a particular element according to your device you can give that element classes like:
<div class="col-md-8 col-sm-4 col-xs-2"></div>
Now this div will have different width depending on the device width.
Media Queries:
Bootstrap 3 use the following media queries in our Less files to create the key breakpoints in grid system.
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
#media (min-width: #screen-sm-min) { ... }
/* Medium devices (desktops, 992px and up) */
#media (min-width: #screen-md-min) { ... }
/* Large devices (large desktops, 1200px and up) */
#media (min-width: #screen-lg-min) { ... }
Media queries will be helpful if you want to change typography or want to override any style according to device
Images:
Images in Bootstrap 3 can be made responsive-friendly via the addition of the .img-responsive class. This applies max-width: 100%; and height: auto; to the image so that it scales nicely to the parent element.
Responsive Utilities
For faster mobile-friendly development, use these utility classes like .visible-xs, .visible-sm etc for showing and hiding content by device. You can simply apply these classes to any element and they will be visible or hidden according to your device

Change content of a view depending on iframe size

My Rails app has a page that can be displayed in an iframe of a third-party website. I would like to change the content of my page based on iframe size. (For example, display only 1 element instead of 3, if the iframe size is small).
Is there a way to do this?
You'll probably want to take a look at media queries.
The basic idea is something like this:
#media (max-width: 768px) {
.hide_on_small_screens { display: none; }
}
You can then add this or similar classes to the objects you want to hide/show. Alternatively you can just write the code for say a class like .iframe_wrapper

Resources