HTML select element with a custom arrow - text comes over the arrow

Discussion in 'CSS' started by xms, Jul 27, 2016.

  1. #1
    So, I have a HTML page with a select element which has a custom arrow. The problem is that the select element text comes over the arrow of the select element. I do not want that. The text should not come over the arrow.

    Here is my CSS code. The default select arrow will be replaced with an own image.

    div.pudotusvalikko {
    width: 95%;
    box-sizing: content-box;
    height: 22px;
    padding: 0;
    overflow: hidden;
    background-color:#FFFFFF;
    background-image: url(/kuvat/arrow22x22.gif);/* width 22 px and height 22 px */
    background-repeat: no-repeat;
    background-position: right center;
    border: 1px solid #999999;
    }
    
    div.seura {
    width: 224px;
    }
    
    div.pudotusvalikko select {
    border: none;
    font-size: 12px;
    padding: 2px;
    width: 110%;
    box-sizing: content-box;
    height: 18px;
    line-height: 18px;
    text-align: left;
    background: transparent;
    background: rgba(0,0,0,0);
    -webkit-appearance: none;
    }
    Code (CSS):
    And here is my HTML code. When the item "Default value of the list is this" is selected, its text will come over the custom select arrow.

    <div class="pudotusvalikko seura">
    <select name="se1"id="se1">
    <option value="1">All</option>
    <option value="2">GUU</option>
    <option value="3">PPP</option>
    <option value="4">SBK</option>
    <option value="5"selected="selected">Default value of the list is this... Default value of the list is this... Default value of the list is this...</option>
    </select>
    </div>
    HTML:
    How should I modify my code if I want that the item text "Default value of the list is this... Default value of the list is this... Default value of the list is this..." will not come over the custom select arrow?
     
    xms, Jul 27, 2016 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,262
    Likes Received:
    1,693
    Best Answers:
    31
    Trophy Points:
    475
    #2
    I am not an expert but I don't believe it's possible to do using css only, since you're dealing with <select> and not a regular div. I know people use javascript and jquery to do that, but with just css... I doubt you can.

    There are all kinds of tricks you can do like having that image as <img> and then placing it over with position: absolute; As an example:

    https://jsfiddle.net/Lp64xdqu/10/

    But then that image isn't going to be clickable and, overall, it's probably a terrible way of doing it anyway.

     
    qwikad.com, Jul 27, 2016 IP