11

How can I create a select element like the below image?

enter image description here

My code is

<select>
    <option>-- Select City --</optoin>
    <option>Delhi</option>
    <option>Gurgaon</option>
</select>

This is available in jQuery, but I want to use pure CSS.

3
  • I'm really not sure what you're asking. You want an image to be behind each of the select options? Commented Apr 17, 2012 at 5:47
  • @Miles yes i want to background images in select options if is possible in pure css ...? Commented Apr 17, 2012 at 5:49
  • Discourage use of dropkick due to the widths issue: stackoverflow.com/questions/11769888/… Commented Aug 2, 2012 at 23:10

5 Answers 5

26

Here is a CSS-powered select menu; you can customize it as you need to:

label.custom-select {
    position: relative;
    display: inline-block;

}

.custom-select select {
    display: inline-block;
    padding: 4px 3px 3px 5px;
    margin: 0;
    font: inherit;
    outline:none; /* remove focus ring from Webkit */
    line-height: 1.2;
    background: #000;
    color:white;
    border:0;
}

/* Select arrow styling */
.custom-select:after {
    content: "▼";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    font-size: 60%;
    line-height: 30px;
    padding: 0 7px;
    background: #000;
    color: white;
    pointer-events: none;
}

.no-pointer-events .custom-select:after {
    content: none;
}
<label class="custom-select">
    <select>
        <option>Sushi</option>
        <option>Blue cheese with crackers</option>
        <option>Steak</option>
        <option>Other</option>
    </select>
</label>

JSFiddle

Sign up to request clarification or add additional context in comments.

Comments

4

Using the pointer-events:none; it will let you click through the arrow and will activate the select field, So the CSS would look like this for that element.

.custom-select:after {
    content: "▼";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    font-size: 60%;
    line-height: 30px;
    padding: 0 7px;
    background: #000;
    color: white;
    pointer-events:none;
}

Comments

0
option{
  background-image:url(image.png);
  background-repeat: no-repeat;
}

Comments

0

There is no way to customise the select as you see it in your screenshot without Javascript.

You can see in this example that you can customise colors, padding and borders, but not the button itself.

Comments

-1

Even though you added a background image to the selectbox, you can not hide that handler on right hand side. I would recommend to use this : http://jamielottering.github.com/DropKick/

You just have to modify the CSS a bit to suit your need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.