'How to apply font family in HTML tag of select option
I am applying Font family in <select><option> tag but it is not working any option guys
My code :
<select name="t1_font" class="form-control" >
<option style="font-family: Font-familly path');">Font-family Name</option>
</select>
My real code that I am using :
<div class="col-sm-4">
<?php $fonts=glob(FONT_URL.'*'); //print_r($fonts); ?>
<?php if (!empty($fonts)): $i=0;?>
<?php foreach ($fonts as $font):
$font_arr= explode('/',$font); $font_string =substr($font_arr[3], 0, -4);?>
<style>
@font-face {
font-family: <?php echo $font_string ?>;
src: url('<?php echo $font ?>');
}
</style>
<?php $i++;
endforeach ?>
<?php endif ?>
<b>Family</b><br>
<select name="t1_font" class="form-control" >
<?php if (!empty($fonts)): ?>
<?php foreach ($fonts as $font): $font_arr= explode('/',$font); $font_string =substr($font_arr[3], 0, -4); ?>
<option style="font-family: <?php echo $font_string ?>;src: url('<?php echo base_url($font) ?>');" value="<?php echo $font_arr[3] ?>" <?php if(!empty($default_data_param->text1))
{if($font_arr[3]== $default_data_param->text1_font_file){ echo'selected';}}?> ><?php echo ucfirst($font_string) ?></option>
<?php endforeach ?>
<?php endif ?>
</select>
</div>
Solution 1:[1]
<select>
<optgroup style="font-family:arial">
<option>Arial</option>
</optgroup>
<optgroup style="font-family:verdana">
<option> veranda </option>
</optgroup>
<optgroup style="font-family:other">
<option>other</option>
</optgroup>
</selecct>
Solution 2:[2]
You have a syntax error in your inline style, the correct syntax is:
option {
font-family: 'sans-serif'
}
or with inline styles:
<option style="font-family: sans-serif">Font-familly Name</option>
- 'sans-serif' should be replace for the font you want.
Solution 3:[3]
Try this: (works for Bootstrap 5)
<div class="">
<label for="fontFamilySelect" class="form-label">Font Family</label>
<select class="form-select" id="fontFamilySelect" onchange="updateFontFamily()">
<option value="">Select</option>
<option disabled style="font-weight: bold; background-color: #EEEEEE">Serif Fonts</option>
<option value="Georgia,serif" style="font-family: Georgia,serif">Georgia</option>
<option value="Palatino Linotype,Book Antiqua,Palatino,serif" style="font-family: Palatino Linotype,Book Antiqua,Palatino,serif">Palatino Linotype</option>
<option value="Times New Roman,Times,serif" style="font-family: Times New Roman,Times,serif">Times New Roman</option>
<option disabled style="font-weight: bold; background-color: #EEEEEE">Sans-Serif Fonts</option>
<option value="Arial,Helvetica,sans-serif" style="font-family: Arial,Helvetica,sans-serif">Arial</option>
<option value="Arial Black,Gadget,sans-serif" style="font-family: Arial Black,Gadget,sans-serif">Arial Black</option>
<option value="Comic Sans MS,cursive,sans-serif" style="font-family: Comic Sans MS,cursive,sans-serif">Comic Sans MS</option>
<option value="Impact,Charcoal,sans-serif" style="font-family: Impact,Charcoal,sans-serif">Impact</option>
<option value="Lucida Sans Unicode,Lucida Grande,sans-serif" style="font-family: Lucida Sans Unicode,Lucida Grande,sans-serif">Lucida Sans Unicode</option>
<option selected="selected" value="Tahoma,Geneva,sans-serif" style="font-family: Tahoma,Geneva,sans-serif">Tahoma</option>
<option value="Trebuchet MS,Helvetica,sans-serif" style="font-family: Trebuchet MS,Helvetica,sans-serif">Trebuchet MS</option>
<option value="Verdana,Geneva,sans-serif" style="font-family: Verdana,Geneva,sans-serif">Verdana</option>
<option disabled style="font-weight: bold; background-color: #EEEEEE">Monospace Fonts</option>
<option value="Courier New,Courier,monospace" style="font-family: Courier New,Courier,monospace">Courier New</option>
<option value="Lucida Console,Monaco,monospace" style="font-family: Lucida Console,Monaco,monospace">Lucida Console</option>
</select>
</div>
Solution 4:[4]
This is how my code run
Insert fonts in head tag
/* BAHAMAS */
@font-face {font-family: 'BAHAMAS'; src: url('../fonts/BAHAMAS0.eot');}
@font-face {font-family: 'BAHAMAS'; src: url(//:) format('no404'), url('../fonts/BAHAMAS0.ttf') format('truetype'); font-weight: normal; font-style: normal;}
call fonts
<option style="font-family:BAHAMAS;">My Font</option>
Solution 5:[5]
#select-group{
font-family: 'samim'!important;}
its cant work in firefox ------But it will work in Chrome!:)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | ianaya89 |
| Solution 3 | OJB1 |
| Solution 4 | |
| Solution 5 | 001100A001100 |

