7
 <select class="Select-input">
   <option value="one">One</option>
   <option value="two">Two</option>
   <option value="three">Three</option>
   <option value="four">Four</option>
 </select>

I want to hide only value four from the above code.

I tried using {display:none} for value-four but it didn't work.

Also want to add padding between this elements one, two, three and four.

P.S. I want to remove it using CSS only.

Danield
  • 121,619
  • 37
  • 226
  • 255
Siren Brown
  • 403
  • 2
  • 5
  • 18
  • 1
    Unfortunately it seems that all of our biggest browsers will disagree on how this should be handled. FF and Chrome will accept display:none and deal with it properly, while IE, Edge and Safari will ignore it. After my own search this is what I've found: https://stackoverflow.com/questions/9234830/how-to-hide-a-option-in-a-select-menu-with-css – Kyle Wilson Sep 22 '17 at 21:26

6 Answers6

11

Attribute selector is the key, although as Musa points out, you can't hide a option in internet explorer.

Article here on hiding option in IE Options with display:none not hidden in IE

   .Select-input option[value=four] {display: none;}
 <select class="Select-input">
   <option value="one">One</option>
   <option value="two">Two</option>
   <option value="three">Three</option>
   <option value="four">Four</option>
 </select>
Community
  • 1
  • 1
Aaron
  • 10,187
  • 3
  • 23
  • 39
4

I took the part Aaron already answered and added the requested padding:

option {padding: 7px 0px 7px 5px;}

option[value=four] {display: none;}
<select class="Select-input">
   <option value="one">One</option>
   <option value="two">Two</option>
   <option value="three">Three</option>
   <option value="four">Four</option>
 </select>
2

You can do this:

CSS

.Select-input option:nth-child(4){
  display: none;
}

DEMO HERE

Luís P. A.
  • 9,524
  • 2
  • 23
  • 36
1

Try this one, may help

select option:last-child {display:none;}
Prajwal Shrestha
  • 524
  • 3
  • 12
0

Try this:

.Select-input option:nth-of-type(2) {
    display:none;
}

Or you can do this to:

.Select-input option:nth-child(1){
   display: none;
 }
The Beast
  • 1
  • 1
  • 2
  • 24
0

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Demo</title>
</head>
<body>

    <select class="Select-input">
      <option value="one">One</option>
      <option value="two">Two</option>
      <option value="three">Three</option>
      <option value="four" style="display:none;">Four</option>
    </select>
  </body>
 </html>

Use inline CSS if you just want to hide just one option using CSS.

If you want to display:block; or display:none; dynamically than use javascript.

Hopefully my contribution will help you.

Sagar Kumar
  • 148
  • 1
  • 8