1

This is killing me. I have 2 select menus that I need to center the text. I've tried varieties of text-align: center, margin: 0 auto, etc. I can't use padding because all of the element's names are different sizes. Any thoughts?

Here is the rails piece of code that makes a select drop down.

<%= collection_select(:id, :name, @restaurants, :id, :name, prompt: "select a restaurant") %>

Here is what the code looks like when produced in html.

<select id="id_name" name="id[name]"><option value="">select a restaurant</option>
  <option value="5">Jamba</option>
  <option value="4">Smokey Joes</option>
  <option value="3">Arbys</option>
  <option value="1">McDonalds</option>
<option value="2">Burger King</option></select>

Current styling. Every time I tried to style option, it did nothing.

.filters{
  height: auto;
  margin: 0 auto;
  overflow: hidden;
  padding-bottom: 10px;
  width: 280px;
  select {
    background-color: rgba(255,255,255,0.71);
    background:-webkit-linear-gradient(bottom,rgba(255,255,255,0.71) 71%, rgba(255,255,255,0.71) 71%);
    background:-o-linear-gradient(bottom,rgba(255,255,255,0.71) 71%, rgba(255,255,255,0.71) 71%);
    background:-moz-linear-gradient(bottom,rgba(255,255,255,0.71) 71%, rgba(255,255,255,0.71) 71%);
    border: 1px solid #fff;
    border-radius: 0;
    color: #553705;
    font-size: 18px;
    height: 48px;
    margin-top: -4px;
    padding: 10px 5px;
    width: 100%;
    -webkit-appearance: none;
    &:hover{
       cursor: pointer;
    }
   }
 }

I also need to add a little drop down arrow in the select, but not sure what element to put the :after on. Here is ideally how I would like the site to look:

enter image description here

Any other thoughts on styling the options would be appreciated too. Right now when I open it, it opens slightly to the side. Here is a picture

enter image description here

LMo
  • 1,429
  • 2
  • 15
  • 32

2 Answers2

0

Its posible with:

select { width: 400px; text-align:center; } select > option { text-center !important; }

Luis
  • 535
  • 2
  • 14
0

Based on this response, https://stackoverflow.com/a/10813603/1949363, it seems not possible to achieve what you need in vanilla CSS. The mentioned post recommends using a jQuery plugin as an option, which doesn't sound all that fun.

Community
  • 1
  • 1
srt32
  • 1,260
  • 1
  • 14
  • 27