Reducing the font size of the drop down in HTML - html

I have dropdown in my HTML Page which has width more than 250px.
I need to change the dropdown font size so that the width gets reduced.
I tried using the font tag like below:
<font size='6'>
<select>
<option></option>
.
.
.
</select>
</font>
The above code didn't work.
When I tried reducing the width by hardcoding the value as width='50' it hides the full text of all the dropdown which becomes hard to select an particular option.
Suggest a solution so that width gets reduced and all the options visible in the dropdown.
Note: it should be compatible in IE8

To change the font size, just apply font-size:XXpx; css property:
<select style="font-size:6px;">
<option>option1</option>
<option>option2</option>
<option>option3</option>
</select>
Or, if you want to put it in your stylesheet:
select{
font-size:6px;
}
<select>
<option>option1</option>
<option>option2</option>
<option>option3</option>
</select>

Use CSS font-size Rule on your select-element
<select style="font-size: 6px">
<option>ABC</option>
<option>ABC</option>
<option>ABC</option>
<option>ABC</option>
</select>
Here's a Fiddle

You can use CSS for that.
Example: https://jsfiddle.net/9ddaexpz/
HTML:
<select id="myDropdown">
<option>foo</option>
<option>bar</option>
</select>
CSS:
#myDropdown
{
font-size: 6px;
}

try this simple method
external style sheet method
select{font-size:6px;}
<select>
<option>option1</option>
<option>option2</option>
<option>option3</option>
</select>
Inline style sheet method
<select style="font-size:6px">
<option>option1</option>
<option>option2</option>
<option>option3</option>
</select>

In select tag use the css style given below.
<select style="font-size:6px">
<option></option>
.
.
.
</select>

Related

Html 5 Select List Option change background color on hover in chrome

Tried a lot to change the background color of select option on hover but unable to do so please help me to find the solution.
select.rangs option:hover {
box-shadow: 0 0 10px 100px #ffea00 inset;}
option.rang:hover {
background: #ffea00 !important;}
<select id="order" name="order" title="order" class="form-control form-login__input-field label-error rangs">
<option class="rang" value="">Sort By</option>
<option class="rang" value="popular">Most popular</option>
<option class="rang" value="register_desc">Oldest First</option>
<option class="rang" value="register_asc">Newest First</option>
I want the background color to be changed on hover in chrome
You cannot change the background of the <option>, you can't set script or style inside option element. This is used to show only text inside option element no matter what text , style or scripts
The main property of option element is value that's why there is no need to add CSS on text inside <option>
You could only apply CSS on <select>:
select {
background: #ffea00;
}
Following code will help you. Run Code Snippet.
.rang:hover { background: #ffea00 !important;}
<select id="order" name="order" title="order" class="form-control form-login__input-field label-error rangs">
<option class="rang" value="">Sort By</option>
<option class="rang" value="popular">Most popular</option>
<option class="rang" value="register_desc">Oldest First</option>
<option class="rang" value="register_asc">Newest First</option>
</select>

How can I make one <option> tag display in a different colour when the <select> is both open and closed?

I have the following HTML:
<select name="selectedEventTypeId">
<option value="1">meeting</option>
<option value="2" selected="" class="ololool">write contract</option>
</select>
And this CSS:
<style type="text/css">
.ololool {color:green}
</style>
However, the option doesn't display in green when the <select> is closed:
It only does when it's open:
I want the second <option> to be green in both views, open and closed. (But I don't want the first option to be displayed in green)
How can I make so?
Try this code
<style type="text/css">
.ololool {color:green}
.blacktext{color:black; }
</style>
<select name="selectedEventTypeId" onchange="this.className=this.options[this.selectedIndex].className" class="blacktext">
<option value="1" class="blacktext">meeting</option>
<option value="2" class="ololool">write contract</option>
</select>
I cant understand very well your question.
But i think that you need to add that class .ololool also to to make it all with the same style.
<select class="ololool">
<option value="2" selected class="ololool" >write contract</option>
</select>

How can I remove background of selectbox

I have to remove background of selectbox, I have used code like this
<select style="background:none;border:none">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select>
But In the output arrow appeared.How can I hide that arrow.
Add -webkit-appearance:none
<select style="background:none;border:none; -webkit-appearance:none">
or add div around and give max width.
<div style="width:80px; overflow:hidden">
<select style="background:none;border:none; width:97px">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select>
</div>
Updated DEMO
Make select width more than 100% and apply overflow:hidden
select {
overflow:hidden;
width: 120%;
}
See this link and the 2nd answer seems more what you are after!
How to remove the arrow from a select element in Firefox

how to give width of ListBox in HTML5

I want to give ListBox width in HTML5.
Please give me some idea.
You can style it as a regular input - all CSS properties applicable to it
DEMO
CSS
input[list] {
width: 300px;
}
HTML
<input type="text" list="browsers" />
<datalist id="browsers">
<option> Chrome </option>
<option> Firefox </option>
<option> IE9 </option>
</datalist>
You can try with
style="width:150px;"
CSS
#example {
width: 300px;
}
HTML
<select size="4" id="example" name="example">
<option selected>Fries</option>
<option>Drink</option>
<option>Pie</option>
<option>Salad</option>
<option>Shake</option>
</select>
For completeness and to show an actual HTML5 Listbox (no JS needed).

shrink width of select, multiple box

One of the items in the multiple select box is much longer than the others, is there a way to hack it to make the width of it smaller
<select size="1">
<option>item</option>
<option>item</option>
<option>item is really long</option>
<option>item</option>
</select>
You can do this with CSS, either in-line style or using a class.
With in-line style:
<select style="width: 50px;">
<option>item</option>
<option>item</option>
<option>item is really long</option>
<option>item</option>
</select>
Using a class:
<select class="narrow">
<option>item</option>
<option>item</option>
<option>item is really long</option>
<option>item</option>
</select>
And in your CSS file or embedded stylesheet:
.narrow {
width: 50px;
}
Of course, change 50px to whatever width you need.
You can set the width using CSS. If you add a class to the select tag, for instance 'foo', you can then add css:
select.foo {
width: 200px;
}
If you want to can use an inline style (not recommended though):
<select style="width: 200px";>
<option>...
</select>
Try this, works in FireFox but not in IE :
<STYLE type="text/css">
OPTION.shorter{ font-size:8px;}
</STYLE>
<select size="1">
<option>item</option>
<option>item</option>
<option class="shorter">item is really long</option>
<option>item</option>
</select>