4

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>
Bindiya Patoliya
  • 2,726
  • 1
  • 16
  • 15
Anand Jain
  • 779
  • 2
  • 10
  • 32

7 Answers7

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.
ianaya89
  • 4,153
  • 3
  • 26
  • 34
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>
0

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>

enter image description here

OJB1
  • 2,245
  • 5
  • 31
  • 63
0

font-family isn't honored in <option> element within <select> dropdown https://bugzilla.mozilla.org/show_bug.cgi?id=1536148

-1
#select-group{
font-family: 'samim'!important;}

its cant work in firefox ------But it will work in Chrome!:)

  • 1
    This answer isn’t very complete. Could you please add some more information to this? For example, where did the ID select-group come from? How does this answer differ to @mohammad-kermani’s answer? – Brook Jordan Jun 13 '21 at 12:33
-2

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>
Mohamed-Yousef
  • 23,946
  • 3
  • 19
  • 28
-4

Update: It seems that this solution does not work anymore! Please see this answer


demo

#select1 {
  font-family: 'sans-serif';
}

#select2 {
  font-family: tahoma;
}

#select3 {
  font-family: monospace;
}
<select id="select1">
        <option>OPTION 1</option>
        <option>OPTION 2</option>
        <option>OPTION 3</option>
    </select>
<br/>
<select id="select2">
        <option>OPTION 1</option>
        <option>OPTION 2</option>
        <option>OPTION 3</option>
    </select>
<br/>
<select id="select3">
        <option>OPTION 1</option>
        <option>OPTION 2</option>
        <option>OPTION 3</option>
    </select>
Mohammad Kermani
  • 5,188
  • 7
  • 37
  • 61