Is it possible to set the font size dynamically?

1

I'm having to develop some views , and frankly I would define my knowledge of CSS as structurally.

I would like to know if it is possible to create a method, without using Javascript, to define the font size to be used in the text dynamically.

Example:

<div class="text-20"> <!-- font-size : 20px; -->
</div>


<div class="text-25"> <!-- font-size : 25px; -->
</div>


<div class="text-15"> <!-- font-size : 15px; -->
</div>

In other words, basically the class would be .text and the -{num} corresponding to the font size.

    
asked by anonymous 01.10.2015 / 22:00

2 answers

0

You have not demonstrated your real need, but why use the class to do this if you can also use the "style" attribute?

<div style="font-size:20px"></div>


<div style="font-size:25px"></div>


<div style="font-size:15px"></div>
    
02.10.2015 / 01:35
0

You can use EM and REM measurement units that are based on the font size of your parent elements and the 'body' element. The units are calculated by dividing the font size you want to use (in px) divided by the font size of your parent element. Example: 16px / 16px = 1em (or rem)

  • EM : Based on your parent element, follow the example

<div style="font-size: 32px">
  <p style="font-size: 1em">Exemplo em EM.</p> 
</div>

In this example, the paragraph will have the size of its parent element "div" that is 32px, the size of 1in will equal 32px.

  • REM : Based on your parent element, 'body'. By default this element has 16px. Here's another example below:

<body style="font-size: 50px">
  <div style="font-size: 32px">
    <p style="font-size: 1rem">Exemplo em REM.</p> 
  </div>
</body>

In the above example, 'p' o 1rem is 50px, influenced by the 'body' element.

    
08.06.2018 / 13:25