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

Bootstrap: Display a single product on the Carousel Product Slider for the smallest view

I found an example I'm using at this link: I noticed that when I resize my BrowserWindow, the boxes start to shrink. However, when the width reaches about 990px, the single products are rearranged in a 4-block layout from the initial width. Is there ...

tips for integrating html5 elements with django forms

I am interested in utilizing the following code: # extra.py in yourproject/app/ from django.db.models import FileField from django.forms import forms from django.template.defaultfilters import filesizeformat from django.utils.translation import ugettext_ ...

Employing negative margin to connect div1 to the left side of div2

Is there a way to attach a dismiss button to the left of a contact in a sidebar? I am trying to achieve a layout similar to the one shown in this image: I attempted using margin-left: -50px; or left: -50px;, but the dismiss div seems to disappear. Even th ...

hitting the value of the text input

Is there a way to strike through only the first word in an input box of type text, without editing the html? I've tried using css text-decoration: line-through; but it's striking both words. Any suggestions on how to achieve this using javascript ...

LabeFor does not automatically create the display-lable class attribute

When setting up a new MVC project, the default Site.css file typically includes the following styles: /* Styles for editor and display helpers ----------------------------------------------------------*/ .display-label, .editor-label { font-weight: ...

Is there a way to share the Username and Password without the need to manually input it?

My goal is to develop a C++ application for my classmates at school. Currently, they are required to visit our school's website and navigate to the login page. Once there, they enter their username and password, log in, and proceed to find their spec ...

Ways to remove the uploaded document

I have been tasked with uploading a file. The file comes with a remove button, which can be pressed to delete it. Below is the code I used: The code snippet is as follows: <div id="main"> <p id="addfile1">Add File</p> <div id ...

Is it possible to determine which child element is currently in view within a scrollable parent div?

In an attempt to replicate a "current page" feature using divs, similar to a PDF reader. document.addEventListener("DOMContentLoaded", function(event) { var container = document.getElementById("container"); container.onscroll = function() { let ...

Utilizing HTML5's geolocation API to construct a geofence

Is there a way to utilize the HTML5 geolocation API to determine if a user is located in a specific area? I'm considering setting a central latitude and longitude and creating a radius around it, so the site will function as long as the user is within ...

styled-components: the parent's styles take precedence over the child's styles

image export const LogOutButton = styled.button` display: inline-block; .... `; export default styled(ThemedApp)` .... button { .... display: flex; .... } `; Upon inspection, it is evident that the Logout button (with class gBuhXv) ...

Displaying incorrect symbols with icon fonts

I have successfully integrated icon fonts into my simple web page. Check it out on jsFiddle here My design is similar to this example, but instead of bars, I see a snake icon displayed. How can I fix this issue with the fonts? Here is the code snippet: ...

Attempting to incorporate Google charts into a div using jQuery's load function

Trying to incorporate a basic Google chart using jQuery .load functionality to transfer the chart into another webpage with a specific containing DIV: <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi">< ...

What methods are available to fill a canvas with shapes other than circles?

My goal is to fill the canvas with a black color. The code I have used for this purpose is as follows: var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.fillStyle='rgba(0,0,0,0.1)'; ctx.fillRect(0,0,c.width,c.height) ...

Issue with border radius in MUI 5 affecting table body and footer elements

Currently, I am diving into a new project utilizing React version 18.2 and MUI 5.10.3 library. My main task involves designing a table with specific styles within one of the components. The table header should not display any border lines. The table body ...

Tips on elevating a dragged div above all other elements when utilizing two scrollbars

Currently, I have two horizontal scrollers where I need to drag a div from the upper scroller to the lower scroller. While this functionality is working properly, there is an issue with the dragged div getting lost under the borders of the scroller during ...

"Place text at the center of a div that is rotated

I'm facing the challenge of centering a heading both vertically and horizontally within a div that has been rotated 45 degrees (transform:rotate(45deg);). Due to this rotation, I have attempted to counteract it by rotating the heading in the opposite ...

Grid of domes, fluid contained within fixed structures and beyond

I've been grappling with this issue for a while now, and have had to rely on jQuery workarounds. I'm curious if there is a way to achieve this using CSS or LESS (possibly with javascript mixins). The page in question consists of both fixed and f ...

Expanding the `div` element to visually occupy the entire vertical space

I'm facing a design challenge with my webpage layout. I have a fixed header and footer, but I need the content section to dynamically adjust its height between the two. The goal is to fill the remaining vertical space with a background-image in the co ...

The issue of HTML email background color not showing up in Gmail, mobile, iOS, or dark mode

Introduction I created the email using MJML code and then converted it to HTML. Everything is functioning correctly, except for the background color not displaying under specific conditions: If the email client is Gmail If the mobile version is being use ...

Difficulty with routing stylesheets in my Node Express server

Currently, I am setting up the back-end structure for my website. The file setup looks like this: public css main.css main_b.css index.hbs index_b.hbs server server.js To reference style sheets in the index files, I use link attributes wit ...