I'm creating a dropdown menu box and arrow. It looks good except one thing. I used :focus so when user is on select the box, it will turn to green. Yes, box is turning to green but when I do the same thing for arrow icon, it is not changing. Can someone help me with this?
All help will be appreciated.
I have searched some solution on the internet but could not fix the problem.
input[type=text],
input[type=tel],
input[type=email] {
width: 100%;
padding: 5px 5px;
height: 40px;
box-sizing: border-box;
border: 2px solid #A9A9A9;
}
/* user input and dropdown turning to green color when active */
input[type=text]:focus,
input[type=tel]:focus,
input[type=email]:focus,
select:focus,
textarea:focus {
width: 100%;
padding: 5px 5px;
height: 40px;
box-sizing: border-box;
border: 2px solid #42AC82;
}
/* dropdown box styling */
select {
width: 100%;
padding: 5px 5px;
height: 40px;
box-sizing: border-box;
border: 2px solid #A9A9A9;
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
}
select::-ms-expand {
display: none;
}
.select-container {
position: relative;
}
select:-moz-focusring {
color: transparent;
text-shadow: 0 0 0 #000;
}
.select-arrow {
color: #A9A9A9;
right: 0px;
top: 7px;
width: 30px;
position: absolute;
display: block;
z-index: 10;
margin: 0 0 0 0;
pointer-events: none;
}
select:required:invalid {
color: gray;
}
select[value=""][disabled] {
display: none;
}
<div class='grid'>
<div class='col col-1-of-4'>Is desicion maker?<br>
<div class="select-container">
<span class="select-arrow fa fa-caret-down" style="font-
size: 1.5em;"></span>
<select name="options" required>
<option value="" disabled selected>Select an option
</option>
<option value="1">yes</option>
<option value="2">no</option>
</select>
</div>
</div>
</div
The reason why you're not seeing the arrow color change is that the arrow icon is not a children or next sibling of select element and there's no CSS selector for previous/ parent element. The way I see it you have two options there:
1) Move you arrow icon after select:
<select name="options" required>
<option value="" disabled selected>Select an
option</option>
<option value="1">yes</option>
<option value="2">no</option>
</select>
<span class="select-arrow fa fa-caret-down" style="font-
size: 1.5em;"></span>
Which should you allow to use + (next sibling) selector
select:focus + .select arrow { color: #42AC82 }
2) Use JS to detect select element focus and toggle class select-container element what would allow you to style all child elements as you need
Try add some of your css like this part:
input[type=text]:focus ~ span ,
input[type=tel]:focus ~ span ,
input[type=email]:focus ~ span ,
select:focus ~ span ,
textarea:focus ~ span {
color: red;
}
And transfer your span with icon after select tag like this:
<select name="options" required>
<option value="" disabled selected>Select an option</option>
<option value="1">yes</option>
<option value="2">no</option>
</select>
<span class="select-arrow fa fa-caret-down" style="font-size: 1.5em;">
</span>
Related
In the example below, if you keyboard navigate to the checkbox, I get the custom focus state I'm looking for. However, I don't want the focus to show on click. I only want to show the focus state when it's keyboard navigated to.
How do I remove the focus state if clicked on?
input[type=checkbox]:focus, input[type=checkbox]:focus-visible {
outline: none;
}
label:focus-within {
outline: 2px solid #005fec;
outline-offset: 4px;
z-index: 10;
}
<label for="check1">
<input type="checkbox" name="check1" id="check1">
<span>Check Here</span>
</label>
Try this!
input[type=checkbox], input[type=checkbox] {
outline: none;
}
<label for="check1">
<input type="checkbox" name="check1" id="check1">
<span>Check Here</span>
</label>
To avoid showing the outline on focus you have to use: outline: none; (https://developer.mozilla.org/de/docs/Web/CSS/outline). In your case you have to add outline: none; only to the class label:focus-within.
label:focus-within {
outline: 2px solid #005fec;
outline-offset: 4px;
z-index: 10;
outline: none;
}
<label for="check1">
<input type="checkbox" name="check1" id="check1">
<span>Check Here</span>
</label>
I changed it to the css solution, but I need to modify the html structure, take the input out of the lable, and modify the css like this
input[type=checkbox]:focus, input[type=checkbox]:focus-visible {
outline: none;
}
input[type=checkbox]:focus, input[type=checkbox]:focus-visible {
outline: none;
}
/* I just added for here for debugging convenience, and now I have removed it
label[for='check2']
*/
label{
padding-left: 25px;
margin-left: -25px;
}
input[type=checkbox]:focus-visible + label{
outline: 2px solid #005fec;
outline-offset: 4px;
z-index: 10;
}
<input type="checkbox" name="check2" id="check2">
<label for="check2">
<span>Check Here2</span>
</label>
How to apply a hover color as the default select option drop in a drop down menu in HTML and CSS?
Does anyone have any idea about it?
This example helps you.(work on Internet Explorer)
option {
font-family: serif;
font-size: 20px;
line-height: 3;
padding: 20px;
}
option:hover {
background: black;
color: red;
}
option:active {
background: yellow;
color: blue;
}
option:focus {
background: green;
colour: orange;
}
<select name="select">
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
<option value="value3">Value 3</option>
</select>
I used custom checkbox and radio button for my project using :before and :after, but this work only in "Google Chrome" and not supported in other browsers, Is any trick that's why it should look same in all browser, I don't want to use label after checkbox or radio button.
CSS is here:
FIDDLE ( For example )
My actual radio button looks like this :
Google Chrome:
Firefox:
IE:
Pseudo Elements like :before and :after add content before and after the content of an element. Checkbox and Radio buttons do not have content, so they don't support before and after pseudo elements. Chrome is ' special ' , but the normal behavior is the one from FF and IE.
Furthermore checkbox and radio are browser default elements. They are very hard to change and not supposed to be changed.
Although you said you don't want to add a label, that's the way to go. Add it with position absolute to put it on top of the radiobutton/checkbox like in the example below
body {
padding: 50px;
}
input[type='radio'] {
margin: 0;
height: 13px;
width: 13px;
margin-top: 2px;
position: relative;
}
div.wrapper {
position: relative;
}
input[type='radio'] + label {
content: '';
display: inline-block;
width: 13px;
height: 13px;
border: none;
position: absolute;
left: 0;
top: 1px;
background: gray url("../images/i-radio-empty.png") no-repeat 0 0;
}
input[type='radio']:checked + label {
width: 13px;
height: 13px;
background: red url("../images/i-radio-checked.png") no-repeat 0 0;
}
<div class="wrapper">
<input type="radio" name="gender" value="male" id="male"> Male
<label for="male"></label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="female" id="female"> Female
<label for="female"></label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="other" id="other"> Other
<label for="other"></label>
</div>
Mihai T's solution isn't bad, but not checking checkbox when cliking on text can be really anoying. I personally hate it :)
Though it is true that radio and chekbox does not support pseudo elemens :before and :after but label does. So you can have normal label with text and pseudo element :before with position: absolute.
div.wrapper {
position: relative;
display: inline-block;
margin-right: 10px;
}
input[type='radio'] {
display: none;
}
input[type='radio'] + label {
padding-left: 20px;
}
input[type='radio'] + label:before {
content: '';
width: 13px;
height: 13px;
position: absolute;
left: 0;
top: 1px;
background: #FFF;
border: 1px solid #999;
border-radius: 50%;
cursor: pointer;
box-sizing: border-box;
}
input[type='radio']:checked + label:before {
background: #000;
border: 4px solid #F9CC55;
}
<div class="wrapper">
<input type="radio" name="gender" value="male" id="male">
<label for="male">Create Tabs Group</label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="female" id="female">
<label for="female">Update Existing Tabs Group</label>
</div>
I have one multiple select with some options inside.
select {
overflow-y:scroll;
height: 200px;
border: 1px solid #c4c7cc;
border-radius: 20px;
margin: 0;
padding: 10px;
color: #323232;
width: 100%;
transition: border-color 0.25s ease;
font-size: 12px;
}
select:not([disabled]):hover,
select:not([disabled]):focus {
border-color: #ff7900;
}
select[disabled] {
opacity: 0.5;
}
<div>
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
My preference is to use default scrollbar and always show vertical scrollbar. But my select has border-radius so when running, the vertical scrollbar hides select's top-right and bottom-right corner.
This works well in IE11 because there is enough space in IE11 for the scrollbar not hiding the corners. But in Chrome, it overlays.
I have tried ::-webkit-scrollbar but it always ask me to use customized scrollbar, which I don't want.
So the question is how to make space in select between scrollbar and the border?
https://jsfiddle.net/x2eqqhqy/
I set border to the parent div instead of select and get the result below.
div {
height: 200px;
border: 1px solid #c4c7cc;
border-radius: 20px;
padding: 10px;
width: 100%;
transition: border-color 0.25s ease;
}
select {
height: 200px;
border:none;
color: #323232;
width: 100%;
font-size: 12px;
}
div:hover{
border-color: #ff7900;
}
<div>
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
To hide the corners you must set border-radius on parent, with overflow:hidden. Don't set height on parent. In short, <select> elements are difficult to style cross-browser. Every single select/dropdown library hides the <select> and draws a surrogate using easier to style elements (typically divs and spans) and than copies the selection to the hidden <select>, using JavasScript.
Here's the closest to what you want, without using a plugin:
select {
overflow-y: scroll;
height: 200px;
margin: 0;
padding: 10px;
color: #323232;
width: 100%;
font-size: 12px;
border-radius: 20px;
border-color: transparent;
outline: none;
}
select[disabled] {
opacity: 0.5;
}
div {
border: 1px solid #c4c7cc;
border-radius: 20px;
transition: border-color 0.25s ease;
overflow: hidden;
}
div:hover,
div:active {
border-color: #ff7900;
}
<div>
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
Apply same border-radius to parent and give overflow: hidden like this:
div {
border-radius: 20px;
overflow: hidden;
}
select {
border-radius: 20px;
}
Regarding this question and this question, My problem still hasn't been solved.
The solution removed everything including the values, arrows and borders.
My code goes like this.
.form-control {
display: block;
width: 100%;
height: 28px;
padding: 6px 12px;
font-size: 12px;
line-height: 12;
color: #666;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
margin-top:5px;
-webkit-appearance:caret;
}
<select class="form-control" value="number">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
if you intend to re-style the select input, you can implement -webkit-appearance: none, and add your own style:
.custom-select{
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: 2px solid #333;
padding: 10px;
min-width: 200px;
border-radius: 0;
/* Add your own arrow image and set it as a background image */
}
<select class="custom-select" value="number">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
The method above will work on -webkit based browser like chrome, safari. But in firefox there still a bug, it's still showing the ugly arrow.