Akshay Antony
Akshay Antony

Reputation: 453

Replacing default icon of select tag and clicking on dropdown icon doesnot populate dropdown list

I have a piece of html code using the select tag. I need to override the default dropdown icon with a new segoe icon. I did that using the following code:

.select {
  border: 1px solid #ccc;
  overflow: hidden;
  height: 40px;
  width: 240px;
  position: relative;
  display: block;
}

select {
  height: 40px;
  padding: 5px;
  border: 0;
  font-size: 16px;
  width: 240px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.select:after {
  content: "\e0e5";
  font-family: segoe mdl2 assets;
  color: #000;
  padding: 12px 8px;
  position: absolute;
  right: 0;
  top: 0;
  background: red;
  z-index: 1;
  text-align: center;
  width: 10%;
  height: 100%;
  box-sizing: border-box;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<label class="select">
    <select name="email" id="email">
        <option>aaaa1</option>
        <option>aaaa2</option>
        <option>aaaa3</option>
        <option>aaaa4</option>
        <option>aaaa5</option>
        <option>aaaa6</option>
    </select>
</label>

My problem is, when clicking on the new dropdown icon, the dropdown list doesn't populate. As it is like an icon over the select option tag. I tried to use z-index but it moves the icon completely to back. Can someone provide a solution?

Upvotes: 3

Views: 1105

Answers (2)

Lalji Tadhani
Lalji Tadhani

Reputation: 14149

Changes Some css

select{
    height: 40px;
    padding: 5px;
    border: 0;
    font-size: 16px;
    width: 240px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    z-index:1; /*Add Z-index*/
    position:relative; /*Add Position*/
    background:transparent; /*Add Background*/
}
.select:after {
    content:"\e0e5";
    font-family: segoe mdl2 assets;
    color: #000;
    padding: 12px 8px;
    position: absolute;
    right: 0;
    top: 0;
    background: red;
    /*z-index:1;*/ /*Remove Z-index */
    text-align: center;
    width: 10%;
    height: 100%;
    box-sizing: border-box;
}

https://jsfiddle.net/yqmb3wxL/

Upvotes: 1

Akshay Antony
Akshay Antony

Reputation: 453

I found the solution. By adding a CSS property

.select:after { 
    pointer-events: none;   
}

in addition to all the CSS properties above, it works.

Upvotes: 4

Related Questions