Skip to content
Fix Code Error

Responsive font size in CSS

March 13, 2021 by Code Error
Posted By: Anonymous

I’ve created a site using the Zurb Foundation 3 grid. Each page has a large h1:

body {
  font-size: 100%
}

/* Headers */

h1 {
  font-size: 6.2em;
  font-weight: 500;
}
<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 accommodate 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?

Solution

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 320 pixels width for wherever your design starts breaking:

@media only screen and (max-width: 320px) {

   body { 
      font-size: 2em; 
   }

}

Viewport percentage lengths

You can also use viewport percentage lengths such as vw, vh, vmin and vmax. The official W3C document for this states:

The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they are scaled accordingly.

Again, from the same W3C document each individual unit can be defined as below:

vw unit – Equal to 1% of the width of the initial containing block.

vh unit – Equal to 1% of the height of the initial containing block.

vmin unit – Equal to the smaller of vw or vh.

vmax unit – Equal to the larger of vw or vh.

And they are used in exactly the same way as any other CSS value:

.text {
  font-size: 3vw;
}

.other-text {
  font-size: 5vh;
}

Compatibility is relatively good as can be seen here. However, some versions of Internet Explorer and Edge don’t support vmax. Also, iOS 6 and 7 have an issue with the vh unit, which was fixed in iOS 8.

Answered By: Anonymous

Related Articles

  • Centering in CSS Grid
  • A minizinc function that checks the neighbors for…
  • CSS Grid Layout not working in IE11 even with prefixes
  • center 3 items on 2 lines
  • How to specify height of nested web component custom…
  • Fix top buttons on scroll of list below
  • CSS grid wrapping
  • Custom event for Foundation 5 top bar dropdown items
  • flutter - add network images in a pdf while creating…
  • DataTable draw daterange from vaadin-date-picker in polymer
  • VueJS masonry layout
  • Unresponsive hamburger icon in HTML
  • jQuery Mobile: document ready vs. page events
  • React Multi-level push menu SCSS Back button not working
  • How do I add foundation with grunt to a ember.js app…
  • Adobe XD to responsive html
  • Javascript validate all checkboxes are selected
  • Active tab issue on page load HTML
  • Why my "title" bloc doesn't go to bottom?
  • The image I am adding as a button in Tkinter is not…
  • JavaScript Code not running on a Live Sever nor Local Host
  • Web components and JS DOM Elements with a placeholder
  • Sort table rows In Bootstrap
  • How to change the color of paper-scroll-header-panel?
  • After a little scroll, the sticky navbar just is not…
  • validateDOMNesting(...): cannot appear as a child of problem
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • How to get main JQuery Mobile page to display after…
  • Animating Elements in One by One
  • How to register Foundation 5 as AMD module with Require.js
  • Polymer data binding with Javascript and attributes
  • How to show title in hover - css / jquery
  • Increasing size of semi circle using css
  • Reactjs Slicing and keeping indexes
  • Deviantart style image gallery CSS
  • Can't correctly import external JS into Aurelia…
  • Vertical scroll inside paper-header-panel behaving…
  • Responsive two column css grid
  • force css grid container to fill full screen of device
  • How to make all controls resize accordingly…
  • HTML table with 100% width, with vertical scroll…
  • Polymer Vaadin Grid v2 migration
  • Having trouble with my nav bar/header, It used to…
  • Azure Sql : Unable to Replace HTML String
  • vaadin-grid selection not working
  • Foundation.js dropdown menu in Ember.js
  • I use useState hock to store the value but it did not update
  • Is it possible to apply CSS to half of a character?
  • Scrollable Menu with Bootstrap - Menu expanding its…
  • When tab is selected, show next tab.. if last tab…
  • Daisy is overlapping the other contents of the div
  • Python Tkinter Spinboxes return value using for loops
  • Onclick event not happening when slick slider is…
  • How to highlight border color of input when on…
  • Recommended website resolution (width and height)?
  • I cant get my type writer heading to the center of my code
  • Aurelia is emitting different css code in Foundation…
  • Vertically align an image inside a div with…
  • Avoid creating new session on each axios request laravel
  • How to use html template with vue.js
  • Pygame enemy not staying at the intended position on the map
  • vaadin-grid-filter for an Array of Strings not working
  • Prevent content from expanding grid items
  • Tailswind css - "list-disc" is not styling bullets…
  • How to build a dynamic CSS grid with Vue?
  • PysimpleGUI Calc not using function properly
  • Mobile browsers add a gap at the end of final…
  • CSS animate a conical gradient as border image
  • Is it possible rotate CSS header and make it…
  • creating multiple frames in tkinter
  • How to create a footer with a logo on the left
  • How to handle vaadin-grid events in custom polymer 2…
  • Change Vue root instance data value on component's…
  • NextJS & json-server loading slow on localhost…
  • NextJS and Formik: Conditional / Dynamic rendering…
  • Reset/remove CSS styles for element only
  • Make Iframe to fit 100% of container's remaining height
  • Show div on scrollDown after 800px
  • Polymer nest 'drawer' inside 'main'
  • How to load data in to rowData in ag-grid?
  • How to make Javascript font responsive?
  • Using jQWidgets in Aurelia
  • How to use core-scroll-header-panel with core-list
  • Firebase cloud function onUpdate is triggered but…
  • Is there any way to reload a page with a button…
  • Equal height rows in CSS Grid Layout
  • Comparison between Corona, Phonegap, Titanium
  • Backbone.js + KendoUI - Routing, Views, and…
  • Font scaling based on width of container
  • Columns side by side with css grid
  • Webpack: How do I include a node module's css?
  • How to add fonts to create-react-app based projects?
  • Polymer change core-toolbar from tall to normal
  • Vuetify grid system row management
  • How to get Google fonts (Varela Round) to work in…
  • Bootstrap Carousel Full Screen
  • URL to node_modules when using Aurelia KendoUI…
  • Jquery populate text box value based on selectbox
  • CSS flexbox fill available space to the right side…
  • Handling scrolling using iron-scroll-threshold in…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Lost httpd.conf file located apache

Next Post:

How to convert Java String into byte[]?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error