4

Facing problem with the font-size setting issue. for sake of better readability I am changing my font-size for different devices i.e mobile,tablets and extra small devices in this way my css is increasing that is fatal for page speed and optimization as well.I just want to adjust my font-size automatically according to container size. Here is my example code which i am writing for different devices and images for output to understand the problem desktop view mobile view with ugly output

.heading{font-size: 50px;}

@media all and (min-width: 768px) and (max-width: 800px){
  .heading{font-size: 40px;}
}

@media all and (min-width: 400px) and (max-width: 480px){
  .heading{font-size: 30px;}
}

@media all and (min-width: 320px) and (max-width: 375px){
 .heading{font-size: 20px;}
}
<h1 class="heading">Font size issue for different devices</h1>
Muhammad Muzamil
  • 1,013
  • 2
  • 18
  • 25

3 Answers3

0

.heading {
  font-size: 50px;
}

@media (max-width: 800px) {
  .heading {
    font-size: 40px;
  }
}

@media (max-width: 480px) {
  .heading {
    font-size: 30px;
  }
}

@media (max-width: 375px) {
  .heading {
    font-size: 20px;
  }
}
<h1 class="heading">Font size issue for different devices</h1>

When you use media query use only @media (parameter) Or use

.heading{font-size: 100%;}
Alireza
  • 100,211
  • 27
  • 269
  • 172
0
**.heading{font-size: 20vw;}
==============
@media (max-width: 800px){
  .heading{font-size: 16vw;}
}
==============
@media (max-width: 480px){
  .heading{font-size: 14vw;}
}
==============
@media (max-width: 375px){
 .heading{font-size: 12vw;}
}
==============
 - List item
# vw doest not support in safari browser #
Aniket
  • 51
  • 5
0

Use em for responsive websites. The em is a scalable unit that is used in web document media. An em is equal to the current font-size, for instance, if the font-size of the document is 12pt, 1em is equal to 12pt

.heading{font-size: 1.6em;}

@media (max-width: 800px){
  .heading{font-size: 1.4;}
}

@media (max-width: 480px){
  .heading{font-size: 1.2em;}
}

@media (max-width: 375px){
 .heading{font-size: 1em;}
}
<h1 class="heading">Font size issue for different devices</h1>
Gerard
  • 15,418
  • 5
  • 30
  • 52
  • The em may be scalable, but that still won't automatically change the font-size. So this sadly doesn't answer the question asked. – Harry Svensson Jul 12 '17 at 06:56