Font Size in em
Using a slider is easy set a font size control when it is in px but when it is in em is so hard select the correct value. Is possible select the value in px and output in em when 1em = 16px?
Why is it difficult to use the slider for ems??
Is hard select a correct value by example 1.090909090909091em
Using a slider to select a value like that wouldn't make much sense.
I can think of 2 alternatives:
- Use a text field that will allow the user to just enter the value and units they want to use. Then, on your field you can add a custom callback that will take care of the validation. See the example code below.
- Use a slider with
.01steps. This will allow users to select a value of1.09for their ems.
Example validation function for the text field:
function my_custom_validation( $value ) {
// Trim the value
$value = trim( $value );
// The array of valid units
$units = array( 'rem', 'em', 'ex', '%', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ch', 'vh', 'vw', 'vmin', 'vmax' );
foreach ( $units as $unit ) {
// The raw value without the units
$raw_value = str_replace( $unit, '', $value );
// Find what unit we're using
if ( false !== strpos( $value, $unit ) ) {
$unit_used = $unit;
}
}
$unit_used = ( isset( $unit_used ) ) ? $unit_used : '';
$raw_value = (float) $raw_value;
$value = $raw_value . $unit_used;
return $value;
}
For now I'll use option two with 0.005 step. Is possible a slider with 4 decimals?
The best way to answer that is to simply test it yourself. Did you try it?