Changing the text colour of a selected disabled option
This is a my idea for your problem, try this
$(document).ready(function(){ $('#MySelect').val('Zero').change(); });
$('#MySelect').on('change',function(){ $($(this)).css("color", $(this).find("option").css('color','black')); var color = $(this).find("option[value="+$(this).val()+"]").attr('optioncolor'); $($(this)).css("color", color); $($(this)).css("color", $(this).find("option[value="+$(this).val()+"]").css('color',color));});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="MySelect"> <option value="Zero" selected optioncolor="red" >Zero</option> <option value="One" optioncolor="green">One</option> <option value="Two" optioncolor="yellow">Two</option> </select>
Change background color of default (disabled) selected option
To solve this issue without scripting you can't use disabled for your default option. Use hidden instead:
body {
background: #41608c;
}
select {
font-family: 'Source Sans Pro', sans-serif;
font-weight: 300;
font-size: 16px;
width: 300px;
height: 64px;
background: rgba(0, 0, 0, 0.4);
border: none;
margin-top: 1px;
color: rgba(255, 255, 255, 1);
appearance: none;
}
select option {
background: rgba(46, 61, 87, 1);
}
<body>
<select>
<option selected hidden>Default value</option>
<option>Value 1</option>
<option>Value 2</option>
</select>
</body>
Styling disabled select in Chrome
It seems to be working just fine using Chrome 15.
input[disabled] {
color: #933;
background-color: #ffc;
}
Make sure you´ve cleared any cached style sheets.
Created a jsFiddle.
UPDATE
Noticed your question title and updated the example.
It´s seems to be a known issue for Chrome in Windows, see Style disabled multiple select – google chrome
How to style the option of an html select element?
There are only a few style attributes that can be applied to an <option>
element.
This is because this type of element is an example of a "replaced element". They are OS-dependent and are not part of the HTML/browser. It cannot be styled via CSS.
There are replacement plug-ins/libraries that look like a <select>
but are actually composed of regular HTML elements that CAN be styled.
Related Topics
Angular 6 Component Not Showing Up
Call Method from HTML Only One Time in Angular2
How to Force Position Absolute With 100% Width to Fit into Parent Div With Padding
Grid Items Overflow Out of Parent Container Using CSS Grid
Fixed Headers on Scroll Inst Working Correctly in Angular Application
Angular: Using the Ternary Operator in HTML Template
Does Id Have to Be Unique in the Whole Page
Center Image Using Text-Align Center
Fixed Page Header Overlaps In-Page Anchors
Disabled Form Inputs Do Not Appear in the Request
How to Pass Boolean Variable of False in a Url
How to Click a Button on a Website Using Puppeteer Without Any Class, Id ,... Assigned to It
Angular 4 Img Src Is Not Found
Html - How to Get My Text Next to My Icon
How to Set Maximum Height for Table-Cell
How to Stop Background from Jumping to the Top on Modal Toggle
Why Does This CSS Margin-Top Style Not Work
Why Is There an Unexplainable Gap Between These Inline-Block Div Elements