Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS Online Registration Form

Kate Massie
seal-mask
.a{fill-rule:evenodd;}techdegree
Kate Massie
Front End Web Development Techdegree Student 7,062 Points

Styling a select box

Hi, can anyone tell me how to add a border to a select box?

I want to add it on the :focus state. Select:focus isn't working, and neither is :focus with the class of the surrounding div.

I'm working on the Online Registration Form for the third Techdegree project.

Thank you!

2 Answers

Steven Parker
Steven Parker
218,692 Points

Only techdegree students can use your link, but I built a little test using this HTML and CSS:

code.html
<div>
  Focus the box:
  <select name="x" id="x">
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
  </select>
</div>
styles.css
select:focus { border: 4px solid red; }

The border appears as expected when the select box has focus. Maybe it's a browser issue? I'm using Chrome.

Did you mean to use hover instead of focus? I tried that too, it also worked as expected.

Kate Massie
seal-mask
.a{fill-rule:evenodd;}techdegree
Kate Massie
Front End Web Development Techdegree Student 7,062 Points

Hi Steven, thanks for your comment! I'm using Chrome too, and I definitely mean focus. That's the command I'm using, too. I think I might try rebuilding the form; otherwise I have no idea.