Align text within <select> in Firefox

Asked

Viewed 2,600 times

4

I’m trying to line up the text inside a <select> but it is only aligned (by default) using Chrome and IE11 browsers (amazingly enough), only in FF(v27.0.1) that the text is at the top.

I’ve tried to use vertial-align:middle but it hasn’t changed at all.

I’d like it to be aligned vertically without using a padding-top for the element because the same disarray in other browsers.

HTML

<select name="disciplina" id="disciplina">
    <option value="00">Disciplina</option>
</select>

CSS

select {
    width: 200px;
    height: 38px;
}

Jsfiddle.

  • It’s really tricky this, if Voce add a padding gets misaligned in others

  • I actually posted an answer with padding and did not. Now I was curious about the solution

3 answers

8


try using the padding-top and padding-bottom for example jsFiddle

CSS

select {
    padding-top:10px;
    padding-bottom:10px;
    width: 200px;
}

documentation: w3schools

  • Good young man, this explicit that can not have a pre defined value in padding-top, so your answer must be adjusted.

  • Yes, now that you spoke I just saw, is that he made the issue saying that could not use padding well after I have sent the reply... Good morning

  • 1

    Your answer was created to 5 minutes and the edition to 16 minutes, so you were aware of the edition or did not take the trouble to read the need of Alessandro Gomes, Young.

  • I would like to not depend on padding, but in this format you passed I do not need to calculate the height to know the padding top, just need to give the same padding top and bot, for now is the solution to my case, I’ll do some more tests here and if I can’t find a solution without padding, I’ll call you back. Valeeu

  • Okay, I’m also sorry for insisting on padding but that’s the only solution I could find... @Eduardobentorochajunior

  • @Silvioandorinha his answer is the solution he was looking for, but he didn’t want an absolute value and ended up using it. : D

  • 1

    @Eduardobentorochajunior I didn’t want an absolute top, but the way he went, I just need to put the same top and bot that it will always be in the center, you know? That’s why it worked for me..

Show 2 more comments

4

I made an example at Jsfiddle:

HTML

<div class="styled-select">
   <select name="disciplina" id="disciplina">
      <option>Here is the first option</option>

   </select>
</div>

CSS

.styled-select select {
   background: transparent;
   width: 200px;
   padding: 5px;
   font-size: 14px;
   line-height: 1;
   border: 1px solid #CCC;
   border-radius: 0;
   height: 34px;

   }

I got the reference of this website.

  • I had been trying to do this but it hadn’t worked, but your attempt worked perfectly

  • That good! I tried to use several methods, but that was the best.

  • Tip: if you explain because your code solves the problem and put links to documentation, the chances of having the answer accepted increase greatly.

2

You can also use this form and leave the text away from the left.

CSS

select {
    width: 200px;
    padding: 10px 10px 10px 40px;
}

or

select {
    width: 200px;
    padding-top: 10px;
    padding-bottom: 10px;
    padding-left: 40px;
}

Observe: Jsfiddle

Browser other questions tagged

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