Design a personalized select element with a unique background hue

https://i.stack.imgur.com/Dzifp.jpg

Trying to create a navigation with col-md-9 and select tags but facing an issue where adding a background-color to the div causes the green background of the arrow to disappear.

https://i.stack.imgur.com/A4P9Q.png Please disregard the view as button as it will be changed later.

Below is the HTML code used to create the select:

.select-style {
  position: relative;
  padding: 0;
  margin: 0;
  border: 1px solid #ccc;
  width: 120px;
  height: 30px;
  overflow: hidden;
  background: transparent url("https://i.imgur.com/qJolQ2D.png") no-repeat 93% 50%;
}

.select-style select {
  padding: 5px 8px;
  width: 150%;
  border: none;
  background-color: transparent;
  background-image: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.select-style select:focus {
  outline: none;
}

.select-style:after {
  position: absolute;
  content: "";
  width: 30px;
  height: 100%;
  background-color: #90c322!important;
  top: 0;
  right: -1px;
  z-index: -1;
  border-radius: 0 1px 1px 0;
}
<div class="col-md-9 headerdiv">

  <span id="sortby">  Sort By </span>
  <div class="select-style" id="style1">
    <select>
      <option>Position</option>
      <option>Position</option>
    </select>
  </div>
  <span id="show">  Show </span>
  <div class="select-style" id="style2">
    <select>
      <option> 5 per page </option>
      <option>3 per page </option>
    </select>
  </div>

  <button class="right" value="MORE">1</button>
  <button class="right" value="LESS">2</button>
  <div id="viewas"> View As</div>

</div>

Answer №1

In the scenario where the green box is not visible, it could be due to the z-index being set to -1. Changing it to z-index: 1 should make it show up, but there may still be an issue where you have to click outside the green box for the dropdown functionality to work.

.headerdiv{
background-color:lightgray;
}
.select-style {
  position: relative;
  padding: 0;
  margin: 0;
  border: 1px solid #ccc;
  width: 120px;
  height: 30px;
  overflow: hidden;
  background-color:pink;
}
.select-style i{
color:#fff;
position:absolute;
top:8px;
right:10px;
z-index:9999;
font-size:20px;
}

.select-style select {
  padding: 5px 8px;
  width: 150%;
  border: none;
  background-color: transparent;
  background-image: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.select-style select:focus {
  outline: none;
}

.select-style:after {
  position: absolute;
  content: "";
  width: 30px;
  height: 100%;
  background-color: #90c322!important;
  top: 0;
  right: -1px;
  z-index: 1;
  border-radius: 0 1px 1px 0;
}
<link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>
<head>
<meta charset="utf-8>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<div class="col-md-9 headerdiv">

  <span id="sortby">  Sort By </span>
  <div class="select-style" id="style1">
  <i class="fas fa-angle-down"></i>
    <select>
      <option>Position</option>
      <option>Position</option>
    </select>
  </div>
  <span id="show">  Show </span>
  <div class="select-style" id="style2">
  <i class="fas fa-angle-down"></i>
    <select>
      <option> 5 per page </option>
      <option>3 per page </option>
    </select>
  </div>

  <button class="right" value="MORE">1</button>
  <button class="right" value="LESS">2</button>
  <div id="viewas"> View As</div>

</div>
</body>

An alternative approach can also be tried. This idea was inspired by https://codepen.io/vkjgr/pen/VYMeXp.

.headerdiv{
  background-color: lightgray;
}
select {

  /* styling */
  background-color: white;
  border: thin solid blue;
  border-radius: 4px;
  display: inline-block;
  font: inherit;
  line-height: 1.5em;
  padding: 0.5em 3.5em 0.5em 1em;

  /* reset */

  margin: 0;      
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-appearance: none;
  -moz-appearance: none;
}


/* arrows */

select.classic {
  background-image:
    linear-gradient(45deg, transparent 50%, white 50%),
    linear-gradient(135deg, white 50%, transparent 50%),
    linear-gradient(to right, green, green);
  background-position:
    calc(100% - 20px) calc(1em + 2px),
    calc(100% - 15px) calc(1em + 2px),
    100% 0;
  background-size:
    5px 5px,
    5px 5px,
    2.5em 2.5em;
  background-repeat: no-repeat;
}

select.classic:focus {
  background-image:
    linear-gradient(45deg, white 50%, transparent 50%),
    linear-gradient(135deg, transparent 50%, white 50%),
    linear-gradient(to right, green, green);
  background-position:
    calc(100% - 15px) 1em,
    calc(100% - 20px) 1em,
    100% 0;
  background-size:
    5px 5px,
    5px 5px,
    2.5em 2.5em;
  background-repeat: no-repeat;
  border-color: grey;
  outline: 0;
}
<div class="col-md-9 headerdiv">

  <span id="sortby">  Sort By </span>
  <div class="select-style" id="style1">
    <select class="classic">
      <option>Position</option>
      <option>Position</option>
    </select>
  </div>
  <span id="show">  Show </span>
  <div class="select-style" id="style2">
    <select class="classic">
      <option> 5 per page </option>
      <option>3 per page </option>
    </select>
  </div>

  <button class="right" value="MORE">1</button>
  <button class="right" value="LESS">2</button>
  <div id="viewas"> View As</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

Styling the TinyMCE Toolbar within a Div container

While working on creating a unified TinyMCE toolbar that is fixed at the top of multiple containers within a div wrapper, I encountered an issue where the CSS styling of the toolbar was lost after wrapping. The toolbar only displayed hyperlink URLs inste ...

Is it possible to use an angular expression as the ng-click function?

I have been searching everywhere for the answer to this question. Within my code, there is an angular object called column.addOnParams. This object includes a child element named rowClick, which can be accessed using column.addOnParams.rowClick. The val ...

What is the best way to ensure that my cards maintain consistent proportions?

My cards are not maintaining their proportions, causing buttons to pop out of the card and the card dimensions changing. I realize this issue is due to using fixed width and height in combination with flex. I'm struggling to find the best solution to ...

How to retrieve the value from an editable td within a table using Jquery

I am working with a dynamic table that looks like this: <table> <tbody> <tr> <td>1</td> <td contenteditable='true'>Value1</td> </tr> <tr> ...

Safari displays an inexplicable gray border surrounding the <img/> element, despite the actual presence of the image

https://i.stack.imgur.com/4QR52.png There is an unexpected gray border visible around the dropdown image, as seen above. This occurrence has perplexed me because, according to several other queries, this problem arises when the image's src cannot be ...

Using CSS to disable an image map in conjunction with dynamically adjusting CSS styling

On the desktop version of the website, there is an imagemap implemented. However, when the site transitions into tablet or mobile view, the imagemap should be disabled to allow for a simpler navigation area to be displayed. I attempted to use the following ...

Troubleshooting Problems with CSS Span Placement

Challenges with Span Positioning in CSS Currently, I am encountering difficulties while working on the index.html.erb file for an example Rails website. Below is a snippet of the HTML code I am struggling with (please note that this is simply a fabricated ...

Are CSS3 animations limited to working only with Webkit?

Trying to create a CSS3 animation featuring a puzzle piece on my website. Below is the code I'm using. Strangely, the animation only seems to be working on Safari and Chrome. Any tips on how to make it compatible with Firefox and Opera? Appreciate you ...

Designing the appearance of a button in a filefield xtype

I am currently working on a web application where users can upload photos using a fileField. I have been struggling to style the button for this feature, as my attempts so far have not been successful. Initially, I tried using the element inspector to iden ...

Struggling with aligning images in the center while ensuring they remain responsive on various devices

My website has an image with dimensions of 955x955, which is a square size. I want this image to be responsive on all devices, but the section it's in is not squared. This causes the image to look distorted when viewed on smaller screens. The focus of ...

Is there a way for me to receive user inputs, perform mathematical operations on them, and then display the result of the calculation? Additionally, is there a way to ensure that the output value automatically updates

As a newcomer to HTML and JavaScript, I'm unsure how to approach this task. Here is what I have so far: <div class="inputs"> <label for="#arena2v2">2v2 Arena Rating:&#9;</label><input class="pvp" type="number" step="1" m ...

Attempting to align images in Bootstrap image carousel within a Google Sites webpage

Click here for image of issue I am currently working on adjusting the code to ensure that all six images in this Bootstrap Carousel are centered on my updated Google Sites webpage, as opposed to them appearing at the top like shown in the screenshot. Any ...

JavaScript allows for the manipulation of elements within a webpage, which includes accessing elements from one

There is a file that contains a fragment for the navbar. The idea is to have listItems in the navbar, and upon clicking on those listItems, another subnavigationbar should open below it. Below is the code I currently have: <!DOCTYPE html> <html x ...

What steps can be taken to address the build problem with Angular version 13?

Encountering a problem while working with Angular 13: https://i.sstatic.net/CbAUhh6r.png Attempting to build using ng build --configuration=test, however facing errors as mentioned above. Interestingly, if I remove the reference to bootstrap.min.css in t ...

When the mouse hovers over the slider, the final image jumps into view

After successfully building an image slider that displays 2 partial images and 1 full image on hover, I encountered a bug when setting the last image to its full width by default. This caused a temporary gap in the slider as the other images were hovered o ...

Tips for effectively utilizing the page-break property within CSS

I am faced with an issue on my HTML page where multiple angular material cards are being displayed: ... <mat-card class="mat-card-98"> <mat-card-header> <mat-card-title>THIS IS MY TITLE</mat-card-title> < ...

Using Phonegap with Dreamweaver CS5.5

Can anyone tell me what version of Phonegap is used in Dreamweaver CS5.5? I attempted to update the default phonegap.js file with the newest one, but it resulted in errors. Would it be wise to replace the current phonegap.js file with the latest version? ...

Customize Bootstrap 4 borders within a row

I am currently facing an issue with my code, where there is a border at the bottom of every row. Click here to view the code Unfortunately, I have noticed that the border at the bottom of each row does not extend across the full width. This occurs even wh ...

Are there various types of HTML5 document declarations available?

Back in the days when I used to create web pages in XHTML, there were three types of doctype available - strict, transitional, and frameset. Are these different types of doctypes still present in HTML5? ...

What is the best way to align content in the middle of a containing div?

I am struggling with centering text and images inside a div that is 190px x 190px. Despite searching on various platforms, including SO and Google, I have not found a simple solution. Can someone please provide guidance on the easiest way to achieve verti ...