Any simple HTML5 / CSS3 method for hiding selected option text?

dom*_*tal 1 html css

I have an HTML select menu that shows options for different currencies in both abbreviated and long format. E.g.

<select>
    <option selected>USD <span>(United States Dollar)</span></option>
    <option>GBP <span>(Great British Pound)</span></option>
    <option>AUD <span>(Australian Dollar)</span></option>
</select>
Run Code Online (Sandbox Code Playgroud)

Is there any way I can hide the long format text inside the span for the selected option without relying on a library like Select2? E.g.

输出示例

I tried simply using this, but it did nothing:

option:checked span {
  display: none;
}
Run Code Online (Sandbox Code Playgroud)

Chr*_*isM 7

So if you just want to hide the text in the currently selected option (when the dropdown is not 'expanded') then you can just set the width of the element.

select{
  max-width:4em;
  font-family:monospace;
}
Run Code Online (Sandbox Code Playgroud)
<select>
    <option selected>USD (United States Dollar)</option>
    <option>GBP (Great British Pound)</option>
    <option>AUD (Australian Dollar)</option>
</select>
Run Code Online (Sandbox Code Playgroud)

This will only work if the prefix that you want to show is always the same width. So that is why I have set a monospace font. You will also need to make sure your value prefix is always a fixed number of characters. If you wanted to use a different font or variable text you would have to do something cleverer to ensure consistent widths.

If you want to change the dropdown itself, then you will need to modify the values or use some kind of custom dropdown. Some examples: