Letter-spacing on selectbox option not working [duplicate] - html

This question already has answers here:
How to style a select tag's option element?
(6 answers)
Closed 5 years ago.
I tried to add some letter-spacing to the options of a selectbox. It seems that this do not work. To test if i touch the right element I added some color to the option.
letter-spacing
select {
letter-spacing:10px;
}
option {
letter-spacing: 10px;
color: red;
}
<select class="form-control" name="select" id="myselect">
<option value="105">Option 1</option>
<option value="106">Option 2</option>
<option value="107">Option 3</option>
</select>

If you want to style dropdown selection, you will have to use some js lib to do so... There are many browsers, that complety ignore dropdown styling (in addition - mobile browsers will pop up the dropdown list with system visuals - fonts, sizes, color and so on)
Check out something like this http://www.jqueryscript.net/demo/Easy-jQuery-Based-Drop-Down-Builder-EasyDropDown/
I personally don't recommend trying to style native <select><option> for the sake of visual integrity

Related

I want to add background image or image in select list using css and html [duplicate]

This question already has answers here:
CSS background-image issue for <select> & <option>
(3 answers)
Closed 7 days ago.
I want to add background picture for options in select list on all browsers.
CSS styling only working on chrome.
<style>
.label-sm option{
font-size:16px;color:black;background: url('url');
}
</style>
Here is HTML:
<div class="col-sm-3 col-5">
<label class="d-block label-sm" for="wrt">Wrt: <span data-tooltip="Derivative with respect to">🛈</span></label>
<select id="wrt" name="wrt" class="form-control">
<option selected value="x">x</option>
<option value="y">y</option>
<option value="z">z</option>
<option value="u">u</option>
<option value="v">v</option>
<option value="t">t</option>
<option value="w">w</option>
<option value="θ">θ</option>
</select>
</div>
as mentioned in the answer here,
CSS background-image issue for <select> & <option>
"each browser has it's own way to render and create those elements. Some browsers will accept having a background image inside your select, others won't."
you can try using custom selects and options, many libraries provide this,

Set different font-weights for different option values of select menu?

These questions are similar but not the same or are very outdated:
HTML font weight property on OPTION of HTML SELECT
How to style the option of an html "select" element?
How can I change the font-size of a select option?
The goal is to style different options of the same select menu with different font-weights. We only need to support modern browsers.
This code doesn't work, even though answers on Stack Overflow and elsewhere suggest it should in modern browsers like Chrome.
Here's an example of what it looks like when using the answer from #gravgrif, which shows all the options styled the same:
Another alternative that did not help was bundling each option in an optgroup, and styling the optgroup.
<select class="weightMenu" title="Bold options available">
<option value="200" style="font-weight:200">B</option>
<option value="300" style="font-weight:300">B</option>
</select>
The goal is to use native HTML and CSS. No plug-ins.
Although your code works fine - you should move the styles to the CSS rather than inline styling. Note - i made the font weights greater to show the differences better.
.weightMenu option:nth-child(1) {
font-weight:400;
}
.weightMenu option:nth-child(2) {
font-weight:700;
}
.weightMenu option:nth-child(3) {
font-weight:900;
}
<select class="weightMenu" title="Bold options available">
<option value="200">A</option>
<option value="300">B</option>
<option value="400">C</option>
</select>
Using bigger font weight may solve this issue.
This is because lower values for font-weight looks the same.
<select class="weightMenu" title="Bold options available">
<option value="400" style="font-weight:400">A</option>
<option value="700" style="font-weight:700">B</option>
<option value="800" style="font-weight:800">B</option>
</select>

How to capitalize the first letter in the select option using css [duplicate]

This question already has an answer here:
How to capitalize ONLY the first letter of an HTML option element using CSS?
(1 answer)
Closed 7 years ago.
Need to capitalize the first letter of the select box option tag.
Here it is what tried:
HTML:
<select>
<option class="selected">test1</option>
<option>test2</option>
<option>test3</option>
</select>
CSS:
select option.selected::first-letter{
text-transform:capitalize;
}
Try this code. if you want selected option capitalized as well then you can do as below code in HTML. This should work in most browsers.
select option {
text-transform: capitalize;
}
<select>
<option class="selected">Test1</option>
<option>test2</option>
<option>test3</option>
</select>

How can I format <select>'s <option> element?

How can I format <select>'s <option> element? Currently we have to use some plugins, like select2, or chosen, or selectboxit, or selectizr.
These js files are big size if we only need to modify UI of <select>'s <option> element, and don't need to use these libraries other features like, tagging, search etc.
I was able to remove <select>'s arrow so I can use any custom arrow or not. check it at :
How can I hide a <select> arrow in Firefox 30+?
But I did't find any option for improving presentation of elements.
About the most you can do is to color the text and change the background-color.
<select>
<option style="background-color: red;">Opt 1</option>
<option style="background-color: green; color: white;">Opt 2</option>
<option style="background-color: blue; color: white;">Opt 3</option>
</select>
You can try applying additional styles, but it's not a standard thing to do. Some browsers will even ignore styling applied to the select and option tags.

<option selected = "selected"> issues in IE9 [duplicate]

This question already has answers here:
How to change a <select> value from JavaScript
(12 answers)
Closed 9 years ago.
I'm having issues with setting a default value in a dropdown menu in IE9. It seems to work on other browsers. All my searches yielded people trying to use JQuery to set that attribute. But I'm not using JQuery at all. Here's a sample:
<select id="selectType" name="selectType">
<option label="1" selected="selected">1</option>
<option label="2">2</option>
<option label="3">3</option>
</select>
I forgot to add that the problem is that it's displaying a blank field as the default instead of "1".
That should work just fine, although personally I would take into account that selected is a boolean attribute and therefore its presence is all that is required:
<option label="1" selected>1</option>
That being said, I'm not sure label is a valid attribute there. I'm fairly sure they're inteded for <optgroup> tags. Try removing that attribute.