Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement responsive typography with Bootstrap 4?

I'm building a responsive web app with Bootstrap 4. I want the font size of all text to be reduced on mobile devices compared to desktop, so I added the following to my base css file as per the Bootstrap documentation (https://getbootstrap.com/docs/4.0/content/typography/):

 html {
  font-size: 1rem;
}

@include media-breakpoint-up(sm) {
  html {
    font-size: 1.2rem;
  }
}

@include media-breakpoint-up(md) {
  html {
    font-size: 1.4rem;
  }
}

@include media-breakpoint-up(lg) {
  html {
    font-size: 1.6rem;
  }
}

However the font size remains fixed. What am I doing wrong?

like image 808
sean Avatar asked Jan 06 '18 11:01

sean


2 Answers

Not a complete answer, but a good starting point is to enable responsive font sizes in v.4.5

$enable-responsive-font-sizes: true;
@import "../../../node_modules/bootstrap/scss/bootstrap";
like image 147
quasipolynomial Avatar answered Nov 18 '22 15:11

quasipolynomial


I think the easiest way is to use @media Queries. Suppose you want to change the font size responsively for a content with class "class-name" or even for entire html tag, just add your media queries to end of your css file or any place inside it.

Sample code:

/*
####################################################
M E D I A  Q U E R I E S
####################################################
*/

/*
::::::::::::::::::::::::::::::::::::::::::::::::::::
Bootstrap 4 breakpoints
*/

  /* Small devices (landscape phones, 544px and up) */
  @media (min-width: 544px) {  
    .class-name {font-size: 16px;}
  }

  /* Medium devices (tablets, 768px and up) */
  @media (min-width: 768px) {  
    .class-name {font-size: 30px;}
  }

  /* Large devices (desktops, 992px and up) */
  @media (min-width: 992px) { 
    .class-name {font-size: 40px;}
  }

  /* Extra large devices (large desktops, 1200px and up) */
  @media (min-width: 1200px) {  
    .class-name {font-size: 48px;}
  }

more information can be found here

like image 35
Ayman Al-Absi Avatar answered Nov 18 '22 13:11

Ayman Al-Absi