How to add font to a select?

Asked

Viewed 116 times

4

I have the following link:

<link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800">

And I’d like to add her to a select.

I’ve tried putting in CSS select { font-family: Arial} and it doesn’t work.

Would anyone know how to place this source? Below the code I’m using to create the select

<tr>
    <td colspan="2>
        <select name="lead_source" style="color:gray; width:100%; height:50px;" required="required">
            <option style="display:none;" value="" disabled selected>Como chegou até nós?</option>
            <option value="Anuncio" style="color:black">Anuncio</option>
        </select>
    </td>
</tr>

inserir a descrição da imagem aqui

  • Friend, check in your code that line: <td colspan="2> if you’re closing with double quotes getting that way: <td colspan="2">, if you’re not correct. I know it has nothing to do with the question but it can help you with any problems, it was suggested in the question but it may be that your code is like this, without closing double quotes.

2 answers

5


The font you want to add is Open Sans, the code you are setting is to add the Arial font.

That is, you should use a css like this:

select {
    font-family: 'Open Sans', sans-serif;
}

Edited:

I believe you are viewing the placeholder font, which by default is not affected by the above code. Try this:

::-webkit-input-placeholder {
    font-family: 'Open Sans', sans-serif;
}
:-moz-placeholder {
    font-family: 'Open Sans', sans-serif;
}
::-moz-placeholder {
    font-family: 'Open Sans', sans-serif;
}
:-ms-input-placeholder {
    font-family: 'Open Sans', sans-serif;
}

Edited 2

Try to do the online setting then, as in the example below:

<tr>
    <td colspan="2">
        <select name="lead_source" style="color:gray; width:100%; height:50px;" required="required">
            <option style="font-family:'Open Sans', sans-serif; display:none;" value="" disabled selected>Como chegou até nós?</option>
            <option style="font-family:'Open Sans', sans-serif; color:black" value="Anuncio">Anuncio</option>
        </select>
    </td>
</tr>

In case it still doesn’t work, one last attempt, but not recommended, would be to use a !important in select’s own css. Or, there is some other font property overwriting that of select.

  • I added and it didn’t work, I tried to add font-size to increase the letter, and it also doesn’t work.

  • @Guilhermelima I edited my answer, try now

  • Negative Celsom, I’m really using placeholder but only input, not Select.

  • I added the select code to make the question clearer.

  • @Guillermo edited the answer.

  • Trinity, even with this second option still not working.

  • @Guilhermelima then you must have some font property being set in another location that is overwriting it. Or else, browser incompatibility. In which you are testing?

  • Or do the following, in Chrome, Inspecione the element and see in the console what are the properties of font-family that are assigned to it and see if there are any overlapping it.

  • FF, Chrome, IE by Mobile

  • Using the Important I was able to change.

  • But beware of the use of !important because you may lose the hierarchy controller of the css

Show 6 more comments

1

CSS

select{
   font-family: "Open Sans";
}

Now using Inheritance from a Parent Element.

HTML

<div class="form-group">
   <select>
      <option> Teste de Fonte em Select </option>
   </select>
</div>

CSS

div.form-group{
   font-family: "Open Sans";
   font-size: 20px;
}

select{
   font-family: inherit;
   font-size: inherit;
}

The inherit inherits from the Parent element - in this case the div.form-group - the properties. But as said, not all browsers understand this.

  • I added and it didn’t work, I tried to add font-size to increase the letter, and it also doesn’t work.

  • 1

    Which browser are you using ? See if FF and IE is working if you’re using Chrome or Safari.

  • I’m testing on Mobile, FF and Chrome.

  • And does the font work in any of them ? I’ve been searching here and it’s complicated to do it. It seems only with jQuery plugin. Via CSS is done by inheritance, but not all browsers work. I will show an example of inheritance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.