I can't change my dropdown icon from the default "carrot" to a Fontawesome one.
I have read other questions, and yet none will work for me.
<form>
<div class="form-group">
<select disabled class="custom-select">
<option selected>Región Metropolitana</option>
</select>
</div>
<div class="form-group">
<select class="custom-select">
<option selected>Comuna</option>
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>
</form>
.form-group .custom-select:disabled {
background: none;
}
.form-group .custom-select::after {
content: '\f107';
font-family: "Font Awesome\ 5 Free";
font-size: 1em;
font-weight: bold;
pointer-events: none;
position: absolute;
left: auto;
top: 50px;
z-index: 9;
color: red;
}
My dropdown should show this fontawesome icon: https://fontawesome.com/icons/angle-down?style=solid
You can't use ::after with select. I had the same problem as you. The best way to do it is with a CSS background image to customise the arrow. Such as:
select {
background-color: white;
background-image: url('../Images/Generic/arrowDownBlack.png');
background-repeat: no-repeat;
background-position: right 5px center;
background-size: 20px 20px;
}
select::-ms-expand {
display: none; //This gets rid of the arrow in IE.
}
If you use a vector image it will be just as good as font awesome.
To prove that I'm right you could always try adding the ::after to another element. It will show up, just not with select.
Related
I can't adjust the position of the drop-down arrow icon in the select element of HTML, I want to adjust the icon so it's not that close to the right
an image is attached below.
image
You cant move/style the arrow in select statement. You can remove the arrow by using style appearance: none;
More help here.
In this example, I am hiding the default arrow and displaying my own arrow.
<div class="abc">
<select>
<option value="a" selected="">a</option>
<option value="b">b</option>
</select>
</div>
<style>
select{
appearance: textfield;
-webkit-appearance: textfield;
}
.abc {
position: relative;
}
.abc:after {
content: "";
background: #ffffff;
right: 10px;
width: 24px;
height: 23px;
position: absolute;
z-index: 999;
background-image: url(arrow image path);
background-size: contain;
background-repeat: no-repeat;
top: 11px;
}
</style>
I need to create a select box that looks like this:
My Html:
<select class="addSelect">
<option>Some Value</option>
<option>Some Value</option>
<option>Some Value</option>
</select>
My Sass/CSS:
.addSelect {
width: 100%;
background: #fff;
border: none;
#include border-radius(6px, 6px, 6px, 6px);
color: #9A9A9A;
#include appearance(none);
padding: 10px;
font-size: 16px;
}
So I have something like this so far:
Pretty close I'd say! (Not the colours yet of course). So, what I'm struggling with is getting that little downward facing arrow in there. When I said 'appearance: none' I effectively got rid of that dropdown arrow.. (though in chrome it was an upward AND downward facing arrow)... Any tips?
you can achieve this using fontawosme icons an absolute position
.select{
width:200px;
}
select{
width: 100%;
height: 30px;
display: block;
appearance: none;
-webkit-appearance: none;
padding: 0 20px;
line-height: 30px;
}
.select:before {
content: "\f078";
font-family: FontAwesome;
position: absolute;
z-index: 1;
right: 5px;
top: 6px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class='select'>
<select class="addSelect">
<option>Some Value</option>
<option>Some Value</option>
<option>Some Value</option>
</select>
</div>
You could use Bootstrap. They have a ton of css ready for you to use. It is really easy to setup and use. With bootstrap you can get the arrow Up and Down in your dropdown.
http://getbootstrap.com/components/#dropdowns
I set a background image (arrow down) to a select box after setting the webkit-appearance attribute to none. When the option list is opened I want to display another background image (arrow up). Is there a pseudo class or something for it? I couldn't find anything during my research...
you can use the :focus pseudo class.
But this will indicate the "open" state, also when the <select> is selected via tab or an item was just selected. To circumvent this, you maybe use something like select:hover:focus but this is rather ugly and is not a solid solution.
select:focus {
background-color: blue;
color: white;
}
<select>
<option>Click me</option>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
It's not possible to detect if a HTML select element is opened using CSS, or even javascript.
If you wish to customise the arrow symbol of a custom dropdown, your best option is to use a custom dropdown component which maps to a hidden select element.
This post is old, but as today; the ::before and ::after pseudo-class still don't work on select element.
Here's a good opportunity to use the :focus-within pseudo-class. I made this simple codepen demonstrating the use of it.
The codepen
The snippet :
#charset "UTF-8";
.wrapper {
position: relative;
display: inline-block;
}
.wrapper::after {
content: "";
font-family: "Font Awesome 5 Free";
font-weight: 900;
position: absolute;
right: 16px;
top: 22px;
font-size: 18px;
pointer-events: none;
transition: 0.2s ease;
}
.wrapper:focus-within::after {
transform: rotateX(0.5turn) translateY(-2px);
}
.wrapper select {
background: linear-gradient(180deg, #F8F9FB 0%, #F1F2F4 100%);
border: 1px solid var(--grayscale-400);
box-sizing: border-box;
border-radius: 3px;
width: 200px;
left: 2px;
cursor: pointer;
padding: 24px 12px;
font-size: 16px;
appearance: none;
}
.wrapper select:focus {
outline: unset;
}
.wrapper select > option:first-child {
display: none;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"/>
<div class="wrapper">
<select>
<option>Choice Label First</option>
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
<option value="Choice 3">Choice 3</option>
<option value="Choice 4">Choice 4</option>
</select>
</div>
I have a problem with IE & firefox. I believe the effect I wanted to achieve works only on chrome.
The problem is that it displays the dropdown perfectly in chrome like on this picture below:
and in firefox / ie it displays it in this way:
So, basically it keeps the default dropdown arrow.
here is a code:
<select name="gender">
<option value="">Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
and css:
input {
height: 67px;
width: 400px;
border:none;
background:url(../_images/butt-reg.png) no-repeat;
padding: 0 20px;
margin: 0 10px 20px 10px;
text-align:left;
vertical-align: middle;
font-size: 18pt;
color: #666;
I'm sure there is a simple solution to sort it out, but i tried couple of things and nothing was working.
Thank you in advance.
Take a look at Style a Select Box Using Only CSS
Look here: http://result.dabblet.com/gist/3358882/5eeb2b8d4fe6adf243c5c463111d367c7651a029
I have tried to overlay the dropdown button with a custom one by using the after-pseudo-element on the parent node (a label-element in this case). The CSS property pointer-events makes sure that you can still click on the pink button to open the select-control.
Doing this cross-browser using CSS only is real hard (if not impossible) to do. The only way I can think of to style your <select> element is to simulate it. First, insert a hidden text input that'll have the selected value. Here's an example HTML that simulates a dropdown-select element:
<div class = "select">
<div class = "curVal">Gender</div><div class = "arrow">V</div>
<div class = "choices">
<div class = "choice">Male</div>
<div class = "choice">Female</div>
<div class = "choice">Refuse to answer</div>
</div>
</div>
Let's style it:
body {
font-family: 'Arial', Helvetica, Sans-Serif;
}
.select div {
display: inline-block;
}
.curVal {
height: 30px;
width: 150px;
line-height: 30px;
vertical-align: middle;
background-color: rgb(0, 162, 232);
color: white;
}
.arrow {
color: white;
background-color: rgb(0, 140, 200); /* this can be an image */
cursor: pointer;
height: 30px;
line-height: 30px;
vertical-align: middle;
position: absolute;
top: 0px;
}
.choices {
position: absolute;
left: 0px;
top: 30px;
background-color: rgb(255, 127, 39);
color: white;
padding: 3px 3px 3px 3px;
width: 150px;
}
.choices div {
display: block;
cursor: pointer;
}
Some jQuery:
$(document).ready()(function(){
$(".choices").hide();
});
$(".arrow").click(function(event) {
$(".choices").slideToggle("fast");
event.stopPropagation();
});
$(".choice").click(function() {
$(".curVal").html($(this).html());
$(".choices").slideToggle("fast");
event.stopPropagation();
});
$("html").click(function() {
$(".choices").slideUp("fast");
});
Put them all together, you get this: jsFiddle.
I hope that helped you in any manner!
Is there any cross-browser way to italicize select options?
With the following CSS and HTML, FireFox shows the second option in italics, but not the third.
None of the options are italicized in IE 7 or Safari.
<style>
option.bravo
{
font-style: italic;
}
</style>
<select>
<option>Alpha</option>
<option class="bravo">Bravo</option>
<option><i>Charlie</i></option>
<select>
Am I correct in assuming this is not possible?
This page has a nice chart of browser support of styling select, option and optgroup: http://www.electrictoolbox.com/style-select-optgroup-options-css/
According to that, the like the only option style that's cross-browser is color.
#MikeWWyatt
I know it's been a while since you asked, but I created this:
Wrap in a paragraph that is position:relative
Create a element that is position absolute
Have your option be the same color as your select background color
Use jQuery to change the option color to white (or whatever color you want) using .change() as well as hide the
HTML
<p>I am a: <span class='pretend-option'>Please choose one</span>
<select name="example">
<option disabled="disabled" selected="selected">Please choose one</option>
<option value="consumer">Consumer</option>
<option value="supplier">Supplier</option>
<option value="retailer">Retailer</option>
</select>
</p>
jQuery
$('select').change(function () {
$(this).css('color', 'white');
$(this).parent('p').children('.pretend-option').css('z-index', -1);
});
CSS
select, option {
-webkit-appearance: none;
-webkit-border-radius: 0px;
border-radius: 0;
display: block;
}
p {
position: relative;
}
select {
padding: 7px;
background-color: blue;
color: blue;
}
.pretend-option {
position: absolute;
bottom: 0.5em;
color: #fff;
left: 0.5em;
pointer-events: none;
z-index: 1;
font-style: italic;
}
Here's a fiddle if you're interested: https://jsfiddle.net/ej34bea0/