How do I put static text in a select element in html? - html

I currently have a select element as follows:
<select class="select" id="startYear" onChange={(event) => setStartYear(event.target.value)}>
Then I have a bunch of options elements as well. Each looking as follows:
<option value=2017 selected={2017 == startYear}>2017</option>
<option value=2018 selected={2018 == startYear}>2018</option>
//lots of different years continuing on
I'm hoping to make it so that there's a static text that says "Start:" and then the dropdown is just all of the years (without the text). See the image below as an example. Anyone know where I can add the "Start:" text?

You would usually use a label for this kind of thing, where the label is to the left and the select box to the right.
div {
border: 1px solid black;
width: 100px;
border-radius: 15px;
padding: 5px 0 5px 10px
}
select {
border: none
}
<div>
<label for="start">Start: </label>
<select id="start">
<option>2017</option>
</select>
</div>
There is still an arrow there which your example image doesn't show, however, I would argue that you want to have the arrow there to denote that it's a select box/drop down. Without it, there's no indication and it's not friendly UX.

I was able to achieve this effect by surrounding the whole thing in a div, and adding the text and select there. With some css, it looks like a normal select prompt. You may have to fiddle with some of the variables to make it to your liking.
.select{
display: inline-block;
border: 2px solid black;
border-radius: 5px;
padding: 5px;
}
.select select {
display: inline-block;
border: none;
background-color: transparent;
}
.select select:focus-visible{
background-color: transparent;
border: none;
outline: none;
}
.select p {
display: inline-block;
text-align: center;
margin: 0;
}
<div class="select">
<p>Start:</p>
<select>
<option>15432542</option>
<option>54326</option>
<option>654262</option>
</select>
</div>

Related

Remove border from Drop down list

I use this CSS to style drop down:
HTML code:
<div class="rd-navbar-contact-info">
<select class="logout" size="1" name="j_idt8">
<option value="Cream Latte">Help</option>
<option value="Extreme Mocha">Profile Settings</option>
<option value="Buena Vista">Logout</option>
</select>
</div>
.logout {
margin: 50px;
/*border: 1px solid #111;*/
background: transparent;
width: 150px;
padding: 5px 35px 5px 5px;
font-size: 16px;
border: 0px solid #ccc;
height: 34px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: url(http://www.stackoverflow.com/favicon.ico) 96% / 15% no-repeat transparent;
color: white;
}
.logout option {
background-color: black;
}
How i can remove the border of the options list? Or can I change it to black?
i think you should try by removing border property or try by making
border:0px solid #000 it might work
You just can't. The fact is you can edit the select box at your will using CSS, but the drop down list isn't HTML, thus is rendered by the browser and/or operative system the user is using to view your page. You can set attributes such as width, height, number of items and background, but you can't set the font, border attributes and so on.

CSS select option bug

I have problem with select and options, in firefox I see this normal (small), but in google chrome, it's very big and not pretty!
The 2nd photo shows - what I want to see and 1st shows - what I see.
I want in <option>:
font-size: 20px;
I want in <select>:
text-align: center;
<select id="what">
<option value="0">0</option>
<option value="100">100</option>
<option value="1000">1000</option>
</select>
<style>
#what {
width: auto;
height: 60px;
border: 0px solid #333;
appearance: none;
text-align: center;
-moz-appearance: none;
-webkit-appearance: none;
font-size: 45px;
color: red;
background: rgba(0,0,0,0);
border-bottom: 1px solid red;
outline: none;
}
#what > option {
height: 40px;
color: #333;
border: 0px;
}
</style>
Please help.
Trying to style select boxes is going to get you a lot of cross-compatibility trouble. You won't be able to fix this with just CSS.
I'm afraid you're going to need to write or find a custom select box. I had a very similar problem and ended up writing my own with Javascript. But that was a while ago - you might be able to find something open source.

preventing option to inherit select css

I have added a specific color and border for a select box on hover. At the moment the options also take the same color and border when you hover on the select. Both the options and select return to their normal css state upon mouseout. Is there a way to prevent the options from inheriting the hover css of the select box ?
My html -
<div class="roi-provider-list">
<select id="providersList" class="roi-header-select">
<option value="">All providers</option>
<option value="7">BELL MOBILITY</option>
<option value="32">ROGERS WIRELESS</option>
</select>
</div>
CSS -
select.roi-header-select:hover {
background-image: url(../../Images/Icons/arrow_down_orange.png);
background-color: #fff;
border: 1px solid #f68c23;
color: #f68c23;
}
Ive also tried the following but to no avail -
select.roi-header-select:hover > option {
border: 1px solid #c8d1d5;
color: #102938;
cursor: pointer;
}
Also -
select.roi-header-select:hover option {
border: 1px solid #c8d1d5;
color: #102938;
cursor: pointer;
}
Thoughts?
select.roi-header-select option:hover {
your rules
}
Here you should overwrite all rules from select.
You have to add a 100% width and Height like this: height: 100%; width: 100%; to the hover CSS

html select box down arrow looks like mouse

On IE8,9 and 10 a select element looks like the attached picture. The drop down arrow is replaced with something that looks more or less like a mouse.
On Firefox and Chrome it looks like a standard drop down with a down arrow.
I can't find anywhere that I've done anything with CSS to alter selects.
Any suggestions?
<td>
<select id='allocated' name='alloc' onchange='allocChange()'>
<option value='??' selected='selected'>??</option>
<option value='1A' >1A</option>
<option value='1B' >1B</option>
<option value='1C' >1C</option>
<option value='2A' >2A</option>
<option value='2B' >2B</option>
<option value='3A' >3A</option>
</select>
</td>
CSS not a factor - same thing happens even when stylesheet not loaded
It may be by default.. But you can change the arrow using css
.styleSelect select {
background: transparent;
width: 168px;
padding: 5px;
font-size: 16px;
line-height: 1;
border: 0;
border-radius: 0;
height: 34px;
-webkit-appearance: none;
color: #000;
}
.styleSelect {
width: 140px;
height: 34px;
overflow: hidden;
background: url("images/downArrow.png") no-repeat right #fff;
border: 2px solid #000;
}

CSS: Remove Line Height (leading) on larger text

How can I remove the leading from the mandatory span so that the << has no additional space above and below.
The field row occupies a certain height based on the default line-height for the text size, the mandatory field however is taller because the font size is larger. How can I strip out the extra white space above and below the <<?
.fieldRow { /* for illustration only */
border: solid 1px #f00;
}
.mandatory {
color: #f00;
border: solid 1px #f00; /* for illustration only */
font-size: 24px;
line-height: 0;
vertical-align: middle;
}
<div class="fieldRow">
<label for="select">Some field</label>
<select name="select">
<option>Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<span class="mandatory">«</span>
</div>
After removing vertical-align: middle it looks good to me.
.mandatory {
color: #f00;
font-size: 24px;
line-height: 0;
}
DEMO
Remove vertical-align
.mandatory {
color: #f00;
border: solid 1px #f00; /* for illustration only */
font-size: 24px;
line-height: 0 !important;
}​
DEMO
I know this is old, but I had a similar problem and came up with a different solution.
It's a bit hacky, but you can put a container around the text, then use overflow hidden and give it a height. The extra space under the larger font will be cut off by the containing div. You're not getting rid of it, but your hiding it. This works for me, may not work in your situation though.
.container {
overflow: hidden;
height: 30px; /* Or whatever height is necessary to show the text */
}
<div class="container">
<span class="mandatory">«</span>
</div>
line-height: unset;
or
line-height: unset !important;
You've added various bits of styling which have added the whitespace in, namely the font-size of the mandatory span is different to it's container.
The border you've added also makes things look a bit worse than they are.
See this fiddle, it looks a lot better when you remove the above.
Revised CSS:
.fieldRow {
border: solid 1px #f00;
font-size: 24px;
}
.mandatory {
color: #f00;
border: solid 1px #f00;
border-top: 0;
border-bottom: 0;
}