After doing some research, I opted for using vw units to scale my responsive typography.
%meta{:content => "width=device-width, initial-scale=1, user-scalable=0", :name => "viewport"}/
css:
html{
font-size: 1vw;
}
// h4 tag above form
h4{
font-size: 1.60rem;
text-align: center;
}
//form width
.e2ma_signup_form {
margin: 0 auto;
width: 36rem;
}
#media screen and (max-device-width: 480px){
html , body{
-webkit-text-size-adjust: none;
}
}
The above shows how I have the root set to 1vw, then i have an h4 tag above a form.
On desktop, i have the length of the text in the h4 tag matching the width of the form (shown in pictures below).
My problem though, is that that on ios, the font does not seem to calculate the same way. Most obviously, where the h4 tag exceeds the width of the form. Seems to work correct on Android.
What could be causing this, and how do I resolve it?
On desktop / chrome emulator (correctly aligned for iphone 6).
On desktop / chrome emulator
on ios, both safari and chrome
on ios, safari and chrome
I have tried to solve this problem too, when I tried to imitate the old-school Flash scaling. I found out that making the font-size relative is not the way to go (although this is how it SHOULD work).
My solution uses javascript/jQuery:
$( window ).resize(function() {
var w = $( window ).width();
var h = $( window ).height();
var wspec = parseInt($( "#innerbody" ).css('width'));
var hspec = parseInt($( "#innerbody" ).css('height'));
if((w/h)>(wspec/hspec)) var scale = h/hspec;
else var scale = w/wspec;
$( "html" ).css('transform','scale('+scale+')');
$( "html" ).css('-ms-transform','scale('+scale+')');
$( "html" ).css('-webkit-transform','scale('+scale+')');
$( "html" ).css('-moz-transform','scale('+scale+')');
});
For a full demo, see this page: http://apps.usecue.com/viewport/flashscaling.html
It's normal that the result is not the same on desktop and mobile as your font-size is based on the viewport width (which is different from mobile to desktop).
If I understand your problem correctly you want your h4 text to never be wider than your form, is this correct? In this case you can't do it in CSS, you need Javascript. You can try Flowtype or FitText (both require jQuery) as they are the ultimate solution for this kind of problems.
You might also be interested in this article about using viewport unit for typography which explains why you can't based your html on viewport unit only (use percentage + viewport unit to define a minimal size).
The last recommendation I can give you is to not use user-scalable. There is a great discussion here on SO about this topic.
As Marco said, browsers render fonts differently.
From your screenshot, I can see that the one from iOS has wider letter spacing. If I were you, I would target the caption line on iOS with something like this:
.caption {
letter-spacing: -1px;
}
From my guts:
Looking at the first screenshot the viewport is as wide as the form element. Thus the text (being set in vw = viewport-width) renders as you expect it.
As soon as the viewport is wider (in the second screenshot there's something behind the form) the text-box becomes wider as well (relative to the viewport width.
Would it help to set the width of the form in vw as well?
On top of that you will always have minor inconsistencies across browsers because they render fonts very differently. Especially Firefox on Mac OSX is so different to all the other browsers on the same machine. So be aware of that as well (shouldn't be too much of an issue compared to yours though).
Edit: On second thought it could also be related to the pixel density of the actual iPhone 6 compared to the emulated version in Chrome (which maybe happens on a different screen with a different pixel density?). That's something OP has not yet mentioned.
According to the table at http://viewportsizes.com/?filter=iPhone%206 the actual iPhone 6 has 375px across in portrait mode. Does that match with the emulation in your Chrome?
Edit2: Data from the actual Apple homepage tells a different story of 1334 x 750 Pixel at 326 ppi!!! So you're not dealing with 375 Pixels but double the number of pixels on the actual device compared to the real 375 pixels on your screen emulating the device.
// We use these to control header font sizes
//for medium screens and above
$h1-font-size: rem-calc(44) !default;
$h2-font-size: rem-calc(37) !default;
$h3-font-size: rem-calc(27) !default;
$h4-font-size: rem-calc(23) !default;
$h5-font-size: rem-calc(18) !default;
$h6-font-size: 1rem !default;
// We use these to control header size reduction on small screens
$h1-font-reduction: rem-calc(10) !default;
$h2-font-reduction: rem-calc(10) !default;
$h3-font-reduction: rem-calc(5) !default;
$h4-font-reduction: rem-calc(5) !default;
$h5-font-reduction: 0 !default;
$h6-font-reduction: 0 !default;
Related
I've been working with tailwind in my Vue project and overall its really good, but its a bit annoying to always write sm:w-10 lg:w-10 2xl:w-30 (etc) for all of my classes.
So I was thinking, since the width is based on rems, wouldn't it make more sense to just update the root font size (which determines rem value) at the lg xl 2xl breakpoints, rather than resetting them on each tag?
I think I could achieve that with something like this on the root component:
html { // changed from body to html
font-size: 16px;
#media screen and (max-width: 1024px) {
html {
font-size: 24px;
}
}
But I'm skeptical about doing this as the Tailwind docs don't mention it at all. Can anyone tell me if/why this would be a bad idea?
Just add it to the parent class then everything under applies the same text modifiers.
Eg below increases the size of text as the screen width goes up for all child divs
<div class='text-base md:text-lg lg:text-lg xl:text-xl'
... All text content inside here will responsively change size
</div>
See below links for more info
Font Size
Responsive Design
I have found an issue which is causing me some confusion. I have font-sizing set across my CSS file with rem scaling, and a base font size of 16px set in the html{ ... } block in the CSS file.
My Issue
When scaling the browser using the browsers own zoom method (Firefox v46 in this case. I have also done this with Chrome v51) the text on the website changes size just fine, however, various padding and a few other elements have scales relating to the font-size, rem value, yet viewing the computed and source code with Firebug (and with Chrome inspector), does not show a zoom-adjusted computed change in these values in px, even when zoomed.
For example:
CSS:
html,body {
font-size: 16px; /*the base.*/
}
nav {
font-size: 0.75rem; /* should be 12px */
}
.textBlock {
font-size: 0.95rem; /* should be 15.2px */
padding: 0 0.15rem; /* should be 2.4px */
}
Now, when I load the page at 100% zoom, everything shows at scale and all computed values are as commented. But if I increase the zoom, for example to 120%, everything textual on the page increases in size proportionally, (while non-font-size-related elements stay consistent), but then reading the page source with firebug, it still tells me that:
code view:
html, body {
font-size: 16px;
}
.textBlock {
font-size: 0.95rem;
padding: 0 0.15rem;
}
Computed results
font-size: 15.2px (in textBlock).
padding: 2.4px (in textBlock).
I want to be able to view the computed size of the elements on the page taking into account the zoom value .
I was under an impression that by changing the zoom of the browser that it altered the body (or html) element base font-size, so that 1rem computed value changes from 16px to 17.5px (for example), and that due to this all related child elements would scale appropriately.
The fonts do scale but I as a browser user I get no feedback on to the current output size of the font based elements on the page.
Further Testing
Using javascript (from this answer) also tells me font size is 16px in the main body, regardless of zoom.
Deleting the body font size does not change anything.
Setting the base body font size to a rem/em value also does not change the feedback given by Firebug, Javascript or Chrome Inspector.
Why don't I read the other font-size questions on StackOverflow
All other (and there are quite a few) font sized questions that I've found relate to people putting static values such as 14px as their element sizes and expecting them to scale.
I can find no useful literature (since 2008/09) about how the browsers actually work the zooming mechanism and how developers can work with this tool.
What Am I trying to achieve/find
I want to be able to view the webpage at any browser zoom level and be able to detect and get feedback telling me the size of the font-size value on various elements, such as:
Zoom 120% on .textBlock [computed] {
font-size: 18.24px; /* (16px * 1.20) * 0.95 */
padding-left: 2.88px; /* (16px * 1.20) * 0.15 */
padding-right: 2.88px; /* (16px * 1.20) * 0.15 */
}
This is more important in my own case for measuring paddings as they're often also rem based in my situation (I am finding that some elements are overflowing due to browser zoom not being 100%). But regardless of my own requirements, I am very surprised that I can't seem to find the computed values I would feel would be pretty basic to need. I want to fix this (and to be honest I can fix my own CSS easily enough, but I wanted to get feedback from reading what the computed font size is, after zoom, but found the issue I post here).
Basically, I want to be able to get quantitive feedback of computed CSS values from a website based on the browser zooming value, of the rem scalar value.
Are there Any solutions to this?
First of all, the rem unit is related to the root element, i.e. html, therefore, changing font-size on body does not have any effect on the descendant elements.
Firebug and the other developer tools display the computed values according to the W3C specification. More precisely, they use the window.getComputedStyle() function to get the computed value and this function does not take the zoom level into account.
To get the actual font size, you need to calculate it yourself. How you do that is described by Tom Bigelajzen. He also created a script to detect the zoom level.
With it you should be able to calculate the actual font sizes by multiplying the computed font size with the zoom factor:
var cs = window.getComputedStyle(element);
var actualSize = Number.parseFloat(cs.fontSize) * detectZoom.zoom();
you can use the pixel ratio to determine the zoom level the user has set it at for example : works in chrome , firefox, edge and brave browser
#media only screen and (min--moz-device-pixel-ratio: 1.25),
(-o-min-device-pixel-ratio: 5/4),
(-webkit-min-device-pixel-ratio: 1.25),
(min-device-pixel-ratio: 1.25) {
I am using Google's web font api with the font "Lato", font-weight of 100.
On the desktop browsers I have tested everything displays fine. However if I view the web page with iPad or iPhone (both iOS5) I notice that the font is extremely thin and the only thing that seems to be displayed correctly are the dots.
I tried implementing the font using the Javascript, LINK-Tag and CSS #import methods, all produce the same results.
I saw that in the FAQs they state:
The Google Web Fonts API works reliably on the vast majority of modern mobile operating systems, including Android 2.2+ and iOS 4.2+ (iPhone, iPad, iPod). Support for earlier iOS versions is limited.
Which means it should work, right?
Is there anyway to solve this?
Thanks
Something I have seen to help really thin Fonts (Incidently also Lato) is this:
-webkit-text-stroke-width: 0.1px;
Anyway it's only a case by case basis, I would use a class / media query to make sure to only apply it when needed (safari(with a class set by js) on a scale under 1.0 or something). Try higher float values if needed.
It seems to me that it's an unlucky combination of an ultra thin typeface with the way Mobile Safari scales the website to fit in the screen. Normally fonts have hinting that allow your computer to interpret how to paint pixels if it gets to subpixel levels, but this is overridden by Mobile Safari's scaling, and thus paints half pixels as semitransparent.
You could prevent mobile safari from downscaling your website by adding the following meta tag:
<meta name="viewport" content="initial-scale=1.0; minimum-scale=1.0">
If you want the font to appear smaller in mobile safari, the solution would be to keep the previous declaration and declare the font size a media query:
#media only screen and (max-device-width: 480px) {
font-size: 15px;
}
If all else fails, I'd add a 0px text shadow:
.selector {
text-shadow: 0 0 0 white;
}
Maybe it's -webkit-text-size-adjust 's fault.
Try
-webkit-text-size-adjust : none
You could try adding this to your CSS for the element in question:
-webkit-font-smoothing: subpixel-antialiased;
Similarly, you may have transforms effecting the antialiasing. You could also try:
-webkit-transform: translate3d(0,0,0);
And even...
-webkit-backface-visibility: hidden;
Crazy, I know.
Are you using Ultra-Light 100? If you set it to 100 but the file is another weight Mobile Safari could be trying to simulate the thinner variant.
Either way, try -webkit-font-smoothing: antialiased;, if that doesn't work you're out of luck, try the 300.
I have a text item on a web page that appears too large in opera browsers. Is there a way to edit text size and other aspects of the css for only opera?
check out this link (scroll down to the part about Opera)
Here
(I never knew this but...) apparently you can use:
#media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {
.operaSpecificStuff { }
}
Opera has a bug in font size defined by em or %. Just reset the font size like this:
body { font-size: 16px;}
Opera doesn't allow for font-sizes smaller than 10px – which results in having bigger fonts on small texts in Opera only. This is intended by design as this setting can be changed by the user only.
See the following thread: http://forums.devshed.com/css-help-116/force-opera-to-use-font-size-less-than-10px-or-763589.html
Are there CSS or other reasons why Safari/iPhone would ignore some font-size settings? On my particular website Safari on the iPhone renders some font-size:13px text larger than font-size:15px text. Does it maybe not support font-size on some elements?
Joe's response has some good best practices in it, but I think the problem you're describing centers around the fact that Mobile Safari automatically scales text if it thinks the text will render too small. You can get around this with the CSS property -webkit-text-size-adjust. Here's a sample of how to apply this to your body, just for the iPhone:
#media screen and (max-device-width: 480px){
body{
-webkit-text-size-adjust: none;
}
}
Use 100% instead of None.
normalize.css includes this
Also, make sure you are setting the initial zoom setting to 1 in your viewport meta tag:
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
Also check if you don't have a "width/height" set to the elements you're manipulating, Safari gives sizing precedence over font size in svg's, Chrome and FF don't, it seems, currently at least.
I had the same problem, turns out in the original CSS there was this line:
-webkit-text-size-adjust: 120%;
I had to change it to 100%, and everything was smooth. No need to change all px to em or %%.