Styling the arrow of a CSS select box

Is it possible to place a dropdown arrow inside a select box? I have tried, but the arrow always displays behind the select box. How can I modify the CSS code to position the arrow properly inside the select box?

.form-item-custom-search-types::before {
  content: '';
  display: block;
  border: 9px solid transparent;
  border-top-color: #4d1c73;
  position: absolute;
  /* right: -17px; */
  top: calc(50% - 2px);
}

.form-item-custom-search-types select {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
}
<div class="form-item form-type-select form-item-custom-search-types">
  <label class="element-invisible" for="edit-custom-search-types">Search for </label>
  <select class="custom-search-selector custom-search-types form-select" id="edit-custom-search-types" name="custom_search_types">      <option value="c-all" selected="selected">All</option>
   <option value="c-announcement">Announcements</option>
   <option value="c-article">Articles</option><option value="c-blog">Blogs</option>
   <option value="c-forum">Forums</option>
   <option value="c-gallery">Galleries</option>
   <option value="c-Documents">Documents</option>
  </select>
</div>

Answer №1

To enhance the appearance of the select element, consider adding a background-image using the following CSS code:

.custom-search-selector{
   background: url(http://cdn4.iconfinder.com/data/icons/ionicons/512/icon-arrow-up-b-128.png) no-repeat right;
    background-size: 16%; 
} 

.form-item-custom-search-types select {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
}
/* added */
.custom-search-selector{
       background: url(http://cdn4.iconfinder.com/data/icons/ionicons/512/icon-arrow-up-b-128.png) no-repeat right;
        background-size: 16%; 
    } 
<div class="form-item form-type-select form-item-custom-search-types">
  <label class="element-invisible" for="edit-custom-search-types">Search for </label>
  <select class="custom-search-selector custom-search-types form-select" id="edit-custom-search-types" name="custom_search_types"><option value="c-all" selected="selected">All</option><option value="c-announcement">Announcements</option><option value="c-article">Articles</option><option value="c-blog">Blogs</option><option value="c-forum">Forums</option><option value="c-gallery">Galleries</option><option value="c-Documents">Documents</option></select>

Answer №2

Make sure to include a position:relative declaration in the parent div.

.form-item{ 
  position: relative;
  display: inline-block;
}
.form-item-custom-search-types::before {
      right: 5px;
      top: calc(50% - 3px);
   }

.form-item-custom-search-types::before {
  content: '';
  display: block;
  border: 9px solid transparent;
  border-top-color: #4d1c73;
  position: absolute;
  /* right: -17px; */
  top: calc(50% - 2px);
}

.form-item-custom-search-types select {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
}

/* added */
.form-item {
  position: relative;
  display:inline-block;
}
.form-item-custom-search-types::before {
  right: 5px;
  top: calc(50% - 3px);
}
<div class="form-item form-type-select form-item-custom-search-types">
  <label class="element-invisible" for="edit-custom-search-types">Search for </label>
  <select class="custom-search-selector custom-search-types form-select" id="edit-custom-search-types" name="custom_search_types"><option value="c-all" selected="selected">All</option><option value="c-announcement">Announcements</option><option value="c-article">Articles</option><option value="c-blog">Blogs</option><option value="c-forum">Forums</option><option value="c-gallery">Galleries</option><option value="c-Documents">Documents</option></select>

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

Unable to apply border radius to the div containing the video

Currently, I am attempting to create a video with rounded corners by wrapping the <video> tag in a div element with rounded corners. This method works perfectly in Chrome and Firefox, but unfortunately does not work in Safari. It seems like this ma ...

Why is the parameter value becoming null during an Ajax call?

I am passing a parameter from HTML to JSP, but when I try to retrieve the value in JSP, it returns null. Can someone help me figure out what's wrong with my code and provide any suggestions? The value is successfully displayed in an alert using JavaS ...

Updating the PHP form to include functionality for a reset button and adjusting the logic for

Having some difficulties with my PHP form. I created a simple form that consists of the following logic: if (isset($_POST['submit'])) { } elseif (isset($_POST['confirm'])) { } else { } The form includes a submit button, followed by a ...

Problem of special characters not displaying properly in jQuery HTML code

I have encountered an issue with displaying special characters correctly. Despite my efforts, the characters are not showing up as intended. Here is how I defined it: var grade_value = 'Wešto izšamešđu'; Following that, I execute this code ...

When I click on a link to redirect it, I am confronted with a bizarre rectangle that

When attempting to create redirects using images, I encountered a small issue. Take a look at this screenshot: https://i.sstatic.net/LgStu.pnghttps://i.sstatic.net/eEnNB.png This is the item in question: <p><div><a title="Home" hr ...

Limited access textbox

Is there a way to create a text-box in AngularJS/HTML that is partially readonly? For instance, having the default value as "+91" and making it readonly while allowing users to enter additional values afterwards? ...

"the content does not occupy the entire space of the parent

My TableRow expands across the width of the screen, and within it is a ListView with a layout_width set to match_parent. However, the ListView does not expand properly. This issue arose when I added two buttons in the next TableRow. Even after setting the ...

Troubleshooting problems with Flask's render_template()

I've been working on a Flask web application that requires users to be logged in to access the contents and functionalities. However, I've encountered an issue where, sometimes after logging in, instead of loading the full home page, a blank "abo ...

Alignment of a div at the bottom inside a jumbotron using Bootstrap 4

Searching for answers on how to vertically align a div within a jumbotron, I have come across plenty of solutions for middle alignment but none for bottom alignment. <section id="profileHero"> <div class="container"> <d ...

Learn how to dynamically apply a CSS attribute for a set period of time using jQuery and automatically revert it back to its original state after 2 seconds

Is there a way to apply a CSS attribute to a specific element (like a div) for only 2 seconds? Here is what I have tried so far: HTML: <div class="custom-div">bar</div> <input class="button" type="button" value="press me" /> JQuery: $ ...

What steps can I take to ensure that my server is accessible to all users?

After successfully creating a chat server using Node.JS and hosting it on my LocalHost (127.0.0.1), I realized that only I have access to the chat. To make the chat server accessible to everyone, I want to deploy it on my real server. The real server URLs ...

jQuery does not support CSS pseudo-code

I'm having trouble with my CSS pseudo-code not being recognized by jQuery. Here is the code I'm using: CSS: h1 { background: red; width: 100px; display: inline-block; } h1:after { content:" | "; background:blue; display ...

What steps should I take to create a slider using my image gallery?

I have a unique photo gallery setup that I'm struggling with: As I keep adding photos, the cards in my gallery get smaller and smaller! What I really want is to show only 4 photos at a time and hide the rest, creating a sliding effect. I attempted ad ...

HTML steps for smooth scrolling to the top and bottom of a list

My HTML contains a vertical list with top and bottom arrows positioned nearby. I am looking to implement a function where clicking on the top arrow will move the list up gradually, and clicking on the bottom arrow will move the list down step by step. Belo ...

Apply a style to the div element that contains a TextInput component

As a beginner in the world of React and Material UI, I am currently working with Material UI version "1.0.0-beta.17", React 15.6.2, styled-components 2.0.0, and styled-components-breakpoint 1.0.1. Within a div element, I have two TextInput fields. const ...

Which HTML/CSS class should be chosen to pair with another class for compatibility with IE 6, 7, and 8?

I am struggling to create a clear div box that works seamlessly across various browsers such as Mozilla, Chrome, Opera, IE 9+, and Safari, including older versions like IE 6, 7, and 8. I have achieved success in all browsers except for IE 6, 7, and 8. To ...

My JavaScript/Jquery functions are not running as expected

I need some help creating a simple image rotation feature. I have a folder named comics where the images are stored locally with names like comic_(number). However, when I click my buttons, nothing happens. The previous button doesn't even get disable ...

Personalized 404 Error Page on Repl.it

Is it possible to create a custom 404-not found page for a website built on Repl.it? I understand that typically you would access the .htaccess file if hosting it yourself, but what is the process when using Repl.it? How can I design my own 404-not found p ...

Ensure that the main div remains centered on the page even when the window size is adjusted

Here is the code snippet: <div id="root"> <div id="child1">xxxx</div> <div id="child2">yyyy</div> </div> CSS : #root{ width: 86%; margin: 0 auto; } #root div { width: 50%; float: left; border: ...

Sharing data between different JavaScript files using Knockout.js

I am working with two JavaScript files named FileA.js and FileB.js. Within FileA.js, there is a function called Reports.CompanySearch.InitGrid: function InitGrid(viewModel, emptyInit) { var columns = [ { name: 'CompanyName', ...