MaterializeCSS - Change select option font family - html

I have a select element which looks like this:
<div class="input-field container">
<select>
<option selected>Roboto</option>
<option>Kalam</option>
<option>Karma</option>
<option>Montserrat</option>
</select>
</div>
Now, for every one of them, I want to change the font family to what the actual inner html is, to give a preview of the font you're about to select.
But putting styles directly on the option doesn't work for me.
I found a solution targeting all options from css, however, that wouldn't enable me to achieve the wanted behaviour.
Any suggestions?
Thanks!

I tried with CSS, but didn't seem to work.
You can use javascript to set the style same as the option's value with the style attribute:
document.querySelectorAll(".selectFont option").forEach(function(el){
el.style.fontFamily = el.value;
})
<div class="input-field container">
<select class="selectFont">
<option value="monospace" selected>monospace</option>
<option value="Arial" >Arial</option>
<option value="sans-serif" >sans-serif</option>
</select>
</div>

This is quite old, but I had the exact same problem - I also wanted to change the font family for text in materialize select options, but after much css manipulation I could not get it to work.
I finally found this answer by wahmal - if you add the class 'browser-default' to your select element, it will remove the materialize styling. You can then change the font family of the options. (That said, it won't look like a materialize element any longer if you do this.) Example:
<div>
<select class="browser-default" id="font-dropdown">
<option selected style="font-family: 'courier';">courier</option>
<option style="font-family: 'arial;'">arial</option>
<option style="font-family: 'Verdana;'">Verdana</option>
</select>
<label>Font</label>
</div>
I did not need !important to get it to work. Hope this helps someone.
https://materializecss.com/select.html

Related

To Change Default Select Option Dropdown Design

I have used a select option dropdown which has a default design like below:
<div class="select-wrapper">
<div class="form-group">
<div class="multipleSelection" id="selectQueryTemplateAdd">
<select id="selectQueryTemplate" class="dynamic_Time form-control TaskOverlayDropDown">
<option selected="selected"> Select </option>
<option value="Please confirm the status of the event whether it is resolved. If y....">Please confirm the status of the event whether it is resolved. If ye....</option>
<option value="Narrative mentions that the subj....">Narrative mentions that the subject ...".</option>
</select>
<div class="overSelect"></div>
</div>
</div>
</div>
Is there any way to change its default design like below image:
It should show pointer (hand icon) when we hover on the value
Below background color should be there when we hover.
Want to adjust its height and width
If Dropdown data is long as below, only some part of it should be visible when we open the dropdown list. But full data should be visible as a tooltip when we hover on any value.
You need to use a CSS framework like bootstrap to achieve this kind of styles.
https://getbootstrap.com/

Edit style for :selected option shown in select box

I have not found a solution for styling the selected option inside a <select> tag.
Example:
<select class="cursor-pointer min-w-[160px] custom-black rounded-sm border border-[#d6dce2] focus:outline-none focus:ring-0 focus:border-[#d6dce2] font-bold px-4 text-sm py-2.5">
<option selected disabled hidden>Edit status</option>
<option value="1">Status1</option>
<option value="2">Status2</option>
<option value="3">Status3</option>
<option value="4">Status4</option>
</select>
I'm trying to change the font-style to italic only for "Edit status" option.
The problem is that when I apply 'italic' to the <select> tag, it applies it for all options. Select tag
Adding italic just to this option does not work at all.
Maybe it's possible using jQuery?
Short Answer:
I am not well versed in jQuery, perhaps someone can help you there, but the short answer is there is no way of styling select options.
Long(er) Answer:
<option> elements are styled by your OS -not the browser- so you cannot nest other elements or style them. The Mozilla Web Docs state:
If you really need full control over the option styling, you'll have to either use some kind of library to generate a custom control, or build your own custom control...
See this and this for other questions like this, and this for advanced style tips; maybe you can find an alternative to select, or design your own dropdown with CSS.
Hopefully that helps you out.

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>

Using Bootstrap-select with icons

I want to create an icon drop-down box where I can display icons, their names, and then be able to search through them with Bootstrap select.
In my current state, I have solved both problems, but when Bootstrap-select is enabled the icons stop showing.
<div class="col-sm-7">
<div class="select">
<select class="selectpicker" id="iconpicker" data-live-search="true" style="font-family: premium-solid-icons">
<option value="none" selected="" disabled="disabled">Ingen</option>
<option value='psi-3d-glasses'> 3d Glasses</option>
<option value='psi-3d-glasses2'> 3d Glasses2</option>
</select>
</div>
</div>
I am pretty clueless, but it seems like the Bootstrap-select overwrites the style of the select dropbox.
How can I solve the problem?
I was right, the premium-solid-icons was being overridden by Bootstraps Select,so i had to include that font-family setting into the Bootstrap-Select.css file.
.bootstrap-select {
width: 220px \0; /*IE9 and below*/
font-family: premium-solid-icons;
(etc.)
Thank you for taking your time to read, and i hope this will help someone else in the future.
Consider using the Custom Option Renderer from React Virtualized Select
Get it from here:
https://github.com/bvaughn/react-virtualized-select/
Demo: https://bvaughn.github.io/react-virtualized-select/

Style <select> the same as other form inputs

I have a contact form on my website (http://shopzuinig.nl/contact.html) and i want to put in this piece of HTML to let people choose between our two different locations:
<select name="mydropdown">
<option value="Restaurant/Kookstudio">Restaurant - Kookstudio Dell'Italia</option>
<option value="Antipasti">Dell'Italia Antipasti</option>
</select>
However, I don't know how to style it in the same way as the e-mail and name input. Can someone please help me?
you can't. You can really only change the width, height and font-size. Maybe a few other little things. If you want a completely custom select you will need to fake it with JS or something.