I've created a site using the Zurb Foundation 3 grid. Each page has a large h1.
CSS
body {font-size:100%}
/* Headers */
h1 { font-size:6.2em;font-weight:500; }
HTML
<div class="row">
<div class="twelve columns text-center">
<h1> LARGE HEADER TAGLINE </h1>
</div><!-- End Tagline -->
</div><!-- End Row -->
When I resize the browser to mobile size the large font doesn't adjust and causes the browser to include a horizontal scroll to accomodate for the large text.
I've noticed that on the Zurb Foundation 3 Typography example page, the headers adapt to the browser as it is compressed and expanded.
Am I missing something really obvious? How do I achieve this?
The
font-size
won't respond like this when resizing the browser window. Instead they respond to the browser zoom/type size settings, such as if you press ctrl and + together on the keyboard while in the browser.Media Queries
You would have to look at using media queries to reduce the font-size at certain intervals where it starts breaking your design and creating scrollbars.
For example, try adding this inside your CSS at the bottom, changing the 320px width for wherever your design starts breaking:
Viewport percentage lengths
You can also use viewport percentage lengths such as
vw
,vh
,vmin
andvmax
. The official W3C document for this states:Again, from the same W3C document each individual unit can be defined as below:
And they are used in exactly the same way as any other CSS value:
Compatibility is relatively good as can be seen here. However, some versions of IE and Edge don’t support vmax. Also, iOS 6 and 7 have an issue with the vh unit, which was fixed in iOS 8.
I've been playing around with ways to overcome this issue, and believe I have found a solution:
If you can write your app for IE9+ and all other modern browsers that support CSS calc(), rem units, and vmin units, you can use this to achieve scaleable text without Media Queries:
Here is it in action: http://codepen.io/csuwldcat/pen/qOqVNO
In actual original sass not scss you could use below mixins to automatically set paragraph and all headings font-size.
I like it because it much more compact. And quicker to type. Other than that it provides same functionality. Anyway if you still want to stick to new syntax - scss then feel free to convert my sass to scss here: [CONVERT SASS TO SCSS HERE]
Below I give you four sass mixins. You will have to tweak their settings to your needs.
After you finish playing with settings just make a call on one mixin - which is: +config-and-run-font-generator(). See code below and comments for more info.
I guess you could do it automatically for media query like it is done for header tags but we all use different media query so it would not be appropriate for everyone. I use mobile first design approach so this is how I would do that. Feel free to copy and use this code.
COPY AND PASTE THOSE MIXINS TO YOUR FILE
CONFIGURE ALL MIXINS TO YOUR NEEDS - PLAY WITH IT! :) AND THEN CALL IT ON THE TOP OF YOUR ACTUAL SASS CODE WITH:
This would generate this output. You can customize parameters to generate different sets of results, however because we all use different media query some mixins you will have to edit manually (style and media).
GENERATED CSS:
There are the following ways by which you can achieve this:
These units will autoresize depending upon the width and height of the screen.
There's another approach to responsive font sizes - using rem units.
Later in media queries, you can adjust all fonts sizes by changing base font size:
To make this work in IE7-8 you will have to add a fallback with px units:
If you're developing with LESS, you can create a mixin that will do the math for you.
Rem units support - http://caniuse.com/#feat=rem
Here is something that worked for me. I only tested it on an iPhone.
Whether you have
h1
,h2
, orp
tags put this around your text:This renders a 22pt text on a desktop and it is still readable on the iPhone.