Select Box in HTML now supports the addition of a Background Image, enhancing

Currently, I am trying to customize the select option box using HTML and CSS. My main goal is to incorporate a scroll feature into the option box. However, I have encountered an issue where the image of the checked box remains visible on the screen.

Below is the example code snippet that I am working with:

.selectbox {
    width: 30%;
}
.selectWrapper {
    width: 100%;
    overflow: hidden;
    position: relative;
    border: 1px solid #bbb;
    border-radius: 2px;
    background:#FFFFFF url('https://cdn.iconscout.com/icon/free/png-256/down-chevron-1438184-1216147.png') right 13px center no-repeat;

}

.selectWrapper select {
    padding: 12px 40px 12px 20px;
    font-size: 18px;
    line-height: 18px;
    width: 100%;
    border: none;
    box-shadow: none;
    background: transparent;
    background-image: none;
    -webkit-appearance: none;
    outline: none;
    cursor: pointer;
    -moz-appearance: none;
    text-indent: 0.01px;
    text-overflow: scroll;
}
<div class="selectbox">
<div class="selectWrapper">
<select id="selectOpt" onfocus='this.size=5;' onblur='this.size=1;' onchange='this.size=1; this.blur();'>
<option>Lorem</option>
<option>Parturient</option>
<option>Euismod</option>
... (remaining options)
</select>
</div>
</div>

Answer №1

To enhance the appearance of your selectWrapper, make sure to include the following styles: background-position: 95% 0; and background-size: 40px;

Check out the revised code snippet below:

.selectbox {
  width: 30%;
}

.selectWrapper {
  width: 100%;
  overflow: hidden;
  position: relative;
  border: 1px solid #bbb;
  border-radius: 2px;
  background: #FFFFFF url(https://cdn.iconscout.com/icon/free/png-256/down-chevron-1438184-1216147.png) right 0 center no-repeat;
  background-position: 95% 0;
  background-size: 40px;
}

.selectWrapper select {
  padding: 12px 40px 12px 20px;
  font-size: 18px;
  line-height: 18px;
  width: 100%;
  border: none;
  box-shadow: none;
  background: transparent;
  background-image: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
  -moz-appearance: none;
  text-indent: 0.01px;
  text-overflow: scroll;
}
<div class="selectbox">
  <div class="selectWrapper">
    <select id="selectOpt" onfocus='this.size=5;' onblur='this.size=1;' onchange='this.size=1; this.blur();'>
      <option>Lorem</option>
      <option>Parturient</option>
      <option>Euismod</option>
      <option>Lorem</option>
      <option>Parturient</option>
      <option>Euismod</option>
      <option>Lorem</option>
      <option>Parturient</option>
      <option>Euismod</option>
      <option>Lorem</option>
      <option>Parturient</option>
      <option>Euismod</option>
      <option>Lorem</option>
      <option>Parturient</option>
      <option>Euismod</option>
      <option>Lorem</option>
      <option>Parturient</option>
      <option>Euismod</option>
    </select>
  </div>
</div>

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

Tips for avoiding cursor sticking in css rotate transform in firefox?

I have a unique challenge in this code where I want the user to grab the black square and rotate it around the inner circle. Check out the code snippet here. While attempting to rotate the square, you might notice that the cursor sometimes gets stuck in ...

jquery asynchronous image loading technique

Can images be loaded asynchronously while the page is loading? The images will only be displayed when a user clicks on a button, rather than immediately showing up. As a result, I am curious if it's feasible to preload the images in a cache so that th ...

The contents of a Javascript array are not appearing within a div element

I have developed a program that reads JSON data related to a concert event. The JSON file consists of an object named global, which includes details about the band name and venue. Additionally, there is a tickets object that contains information on all ava ...

programming for the final radio button text entry

I am struggling with a form that has 5 radio buttons, including an "other" option where users can manually enter text. The issue I'm facing is that the form only returns the manual entry text and not any of the preset radio values. I need it to work f ...

implementing a sidebar menu using AngularJS

I am currently working with bootstrap and AngularJS to create a sidebar menu. Here is the code I have for it: <ul class="nav navbar-nav"> <li><a href="#"><span class="glyphicon glyphicon-send"></span> Link</a& ...

With Vue's new implementation of adding data attributes to the "*" selector, how can I adapt to this change?

Typically, I reset all margins/paddings by including the following code snippet at the beginning of my CSS: *, body { margin: 0; padding: 0; } This method usually works fine since it is overridden by subsequent selectors. However, Vue appends data att ...

Is it possible to reset a form without using JavaScript? (The input type=reset function is not functioning correctly

So, basically I need a quick way to clear all the fields in my form. I've experimented with a couple of options: <input type="reset" value="Clear all fields"> And <button type="reset">Clear all fields</button> Unfortunately, none ...

How to use AngularJS to collapse various panels with unique content

Hey everyone, I'm working on developing a collapsible panel using Angular. The panel should consist of a header and body to display the content. The desired behavior is that when a button is clicked, the content collapses down, and clicking the same b ...

A step-by-step guide to displaying a list with material icons in a React JS application utilizing the Material

I tried implementing a dropdown list with Material-UI, including an icon on the left side. However, after following the documentation and adding the code for the icon, the dropdown list stopped working. InputProps={{ startAdornment: ( ...

Troubleshooting: Angular ng-if not correctly detecting empty strings

When looking at my code, I have the following snippet to showcase data from angular scope variables. The initial two lines are functioning correctly and displaying data from the scope variables; however, there seems to be an issue with the line using ng- ...

AngularJS allows users to seamlessly retain any entered form data when redirected, enabling users to pick up right where they left off when returning to the form

I am currently working on a user data collection project that involves filling out multiple forms. Each form has its own dedicated HTML page for personal details, educational details, and more. After entering personal details and clicking next, the data ...

I am looking to display multiple divs sequentially on a webpage using JavaScript

Looking to display a rotating set of alerts or news on my website. The goal is to show each news item for a certain number of seconds before moving on to the next one in line. However, I'm new to javascript and need help creating a code that will cont ...

AngularJS: ng-show causing flickering issue upon page refresh

Recently, I encountered an issue with my code snippet: <body> <ng-view></ng-view> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script> <script src="http://ajax.googleapis.com/ajax/ ...

Ensure the filelist resets each time the bootstrap-modal is hidden or closed

Context I am in the process of developing a form where users can input data and upload an image file. The information entered into the form, along with the file name, is stored in a MySQL database. To style the website, I am utilizing Bootstrap. When a u ...

JavaScript can retrieve the default page name that is hidden within the browser's URL

When a URL is entered without a specific file name at the end, such as "www.google.com," the server typically serves a default file like "index.html" or "default.aspx." In this scenario, if the browser displays "www.google.com," I am looking to extract the ...

Don't let noise linger in the background unnoticed

Within my HTML table, there are 32 cells that each possess an onclick="music()" function. This function is currently functioning correctly, with one small exception. I desire for the functionality to be such that whenever I click on a different cell, the m ...

How to Implement Full Height CSS for Child Elements?

How can I set the child containers "left" and "right" to be 100% height of the parent container, which is already at 100% height? Also, what's the best way to position the container "hexCont" horizontally? CSS: <style type="text/css"> html ...

Choose an item from the list and use the scrollbar when the menu opens

My select element has over 50 options, but the options popup and go off the page without a scroll bar. As a result, I can only see and select up to 20 options. Is there a way to make the select element display a vertical scroll bar when there are more tha ...

How to give a stylish touch to your :after element with a css

I have a unique bubble design that pops up when hovering. I'm trying to add a border around the bubble, but I'm facing difficulty adding a border to the pointer of the bubble. The arrow is created using the .bubble:after selector. You can check ...

Distribute divs of equal width evenly within a grid

I'm facing a unique challenge at the moment. I'm attempting to create a grid system where all elements have a fixed width of 200px each. What I envision is a clever grid setup using only CSS, where each "row" will strive to accommodate as many el ...