Enhancing the appearance of a Select element

Alright, let's break it down:

  • I have a custom styled <select> element
  • I want to display an up arrow (possibly a Bootstrap Glyphicon) on the right side of its transparent background

The problem at hand:

  • The icon appears correctly (though in the fiddle it looks like a square icon, but that's not a big deal)
  • However, when I click on the icon, the select option doesn't get triggered - this is incorrect behavior.

Any thoughts or suggestions?


HTML:

<div id="styled-select">
    <select>
        <option value="one">One</option>
        <option value="two">Two</option>
        <option value="three">Three</option>
    </select>
</div>

CSS:

select {
    border:0; 
    border-radius: 0;
    background:transparent; 
    outline:none; 
    box-shadow:none; 
    -webkit-box-shadow:none; 
    text-align:right;
    -webkit-appearance: none;

    padding-top: 1px;
    font-size: 13px;
    padding-left: 10px;
}

#styled-select:hover {
    color: #666;
}

#styled-select:after {
    content:"\e113";
    font-family:"Glyphicons Halflings";
    line-height:1;
    display:inline-block;
    margin-left:5px;
}

Demo/Fiddle: http://jsfiddle.net/tnzbL1hp/

Answer №1

Just included the following CSS:

select {
    margin-left: 10px;
    padding-left: 15px;
}

and also added:

#custom-select:before {
    content: "Custom Selector";
}

http://jsfiddle.net/abc123def/2/

Answer №2

Just thought of another solution:

    #styled-select:after {
        content:"\e113";
        font-family:"Glyphicons Halflings";
        line-height:1;
        display:inline-block;

        pointer-events:none;

        width: 23px;
        height: 23px;
        position: absolute;
        top: 8px;
        right: 4px;

    }

Also, remember to include some padding-right on the <select> element...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transmit information from javascript to the server

I am currently working on an ASP.NET MVC web application and have a query: If I have a strongly typed view and I submit it, the object (of the strongly type) will be filled and sent to the server. But what if one of the properties of the strongly typed i ...

Dash that serves as a barrier between two words to avoid them from breaking onto

Is there a way to keep a dash ( - ) from breaking a word when it is at the end of a line? Similar to how &nbsp; prevents a line break between two words. The issue I am facing currently is with a dynamic blog post that includes the word X-Ray. Unfortun ...

Unfortunately, the Ajax functionality is not performing as expected

What am I missing? 2.php: <button id = "Text_Example">Display</button> <script src="jquery-3.1.1.min.js"></script> <script src="js_code.js"></script> js_code.js: $("#testtext").bind("click", displayNewData); functio ...

Automatically, the "ng-hide" class gets added despite using the correct syntax for ng-show

I am trying to dynamically show/hide a tr tag within a table based on the value of a scope variable in the controller. Despite writing the code correctly, I am facing an issue where the "ng-hide" class is automatically added to the tr tag every time it is ...

Once the ajax jQuery is triggered, I hope to see an image loading for a brief moment of just 1

Can someone assist me with the following code snippet? <script type="text/javascript"> $(function () { $(".a").live("click", function () { var $this = $(this), ProductImageId = $this.data('ProductImageId'); ...

Using a foreach loop to showcase data in a table

My goal is to utilize the GitHub API to showcase all the issues present in my repository in a neat table format on my website. Despite my best efforts, I am facing difficulties in generating the table using a foreach loop. Below is the PHP code I am curr ...

Image missing aria-label attribute

I am facing an issue with getting the aria-label to display on my image. Despite checking my code, I cannot figure out why it is not working. Any ideas on what might be missing? Here is the code from my NextJS app: The svg in my public folder. <?xml v ...

Incorporating a scrollbar into a CSS content accordion for enhanced user experience

Currently, I am exploring a tutorial for coding a content accordion which can be found here: I am wondering about the possibility of adding endless content to each section while incorporating a scroll bar. Any suggestions on how to achieve this? Apprecia ...

Is there a problem with the refresh method in Javascript not functioning properly in Edge browser?

As I embark on my current project, a challenge presents itself: I require the page to automatically refresh once the music has concluded. Surprisingly, this code performed flawlessly on Chrome and Firefox. setTimeout(location.reload.bind(location), 206000 ...

Reliable Dropdown Navigation Bars

Once I have successfully implemented three dynamic drop down menus using the combination of jQuery, AJAX, and PHP, the next challenge arises. After populating the dropdown menus based on user selections (e.g., selecting a value in the first dropdown menu ...

What is the best way to send a POST request using $.ajax() to an ASP.NET WEB API

Every time I hit the WEB API method, I keep encountering a null parameter. What could be the issue? var product = { name: "productA", Id: 22 }; $.ajax({ url: 'http://localhost:50175/api/values/', type: 'POST', data: produc ...

The AJAX callback is unable to access the method of the jQuery plugin

I have a scenario where I am fetching data from an AJAX response and attempting to update a jQuery plugin with that value within the success callback: $.ajax({ url: '/some/url', type: 'GET', dataType: 'json', succ ...

Surprising sight of a blank canvas behind the font-awesome icon

Is there a way to remove the unexpected white background that appears when adding a font-awesome icon? Here is the HTML code: <div class="notifications-window" id="close-notifications"> <div class="notifications-header&qu ...

Inserting a singular image following a designated list item

I have a question that may seem silly, but I'm trying to understand a specific CSS styling issue. I want to add an image targeting a particular li item. Currently, the code adds the image after all the li items: .menuStyling li:after{ content: u ...

Play a matching game using CSS3 to match and check tiles

Currently in the process of creating a game using HTML5 and CSS3. I'm working with several divs that have hover-activated CSS3 animations. The game itself is a simple matching tiles/cars game, optimized for Chrome as it currently only supports -webki ...

Ways to initiate an ajax event when a checkbox is clicked in ASP.NET MVC

I came across a discussion in the database regarding this topic, but unfortunately there was no demonstration of the concept mentioned Adding a onclick dynamically using an Html Helper in MVC My goal is to trigger ajax when a checkbox is clicked @Html.C ...

Tips for attaching to a library function (such as Golden Layout) and invoking extra functionalities

I am currently utilizing a library named Golden Layout that includes a function called destroy, which closes all application windows on window close or refresh. My requirement is to enhance the functionality of the destroy function by also removing all lo ...

Creating an Ajax Post request for API invocation

I'm currently setting up an Ajax Post request to interact with an API. Here is a mock curl command for reference: curl -X POST \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --h ...

A rapid tool for efficient HTML parsing based on libxml

Hey there, I've encountered an error message that's a bit puzzling - it says "Extra argument 'endocing' in call", even though it's within the method so technically not an extra argument. Any idea why this is happening and how I can ...

The onLoad event of the <picture /> element is not consistently being triggered

I'm encountering an issue where the onLoad event on the picture element is not consistently firing. I have tried adding the onload event listener to both the picture and image elements, but sometimes they both fire and other times neither of them do. ...