Problems with creating placeholders for HTML selection boxes

Problems with creating placeholders for HTML selection boxes

I'm using a placeholder in a text input and it works fine. But I also want to use a placeholder for my select box. Of course, I can use the following code:

<select>
    <option value="">Select your option</option>
    <option value="hurr">Durr</option>
</select>

But the "Choose Your Option" is black instead of light grey. So my solution would probably be CSS based. jQuery is also good.

This will just grey out the options in the dropdown menu (so after clicking the arrow):

option:first {
    color: #999;
}

The question is: How do people create placeholders in select boxes? But it has been answered, hurray.

Using this method causes the selected value to always be greyed out (even after selecting a real option):

select {
    color: #999;
}

Solution:

Non-CSS - no JavaScript/jQuery answer:

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="hurr">Durr</option>
</select>

The above is the detailed content about the problem of creating placeholders in html selection boxes. For more information about html selection box placeholders, please pay attention to other related articles on 123WORDPRESS.COM!

<<:  HTML CSS3 does not stretch the image display effect

>>:  Display special symbols in HTML (with special character correspondence table)

Recommend

Explanation of the usage scenarios of sql and various nosql databases

SQL is the main trunk. Why do I understand it thi...

Examples of using the Li tag in HTML

I hope to align the title on the left and the dat...

Nginx sample code for implementing dynamic and static separation

In combination with the scenario in this article,...

UDP DUP timeout UPD port status detection code example

I have written an example before, a simple UDP se...

A brief analysis of JS original value and reference value issues

Primitive values ​​-> primitive types Number S...

Solution to the problem of not finding Tomcat configuration in Intelli Idea

I joined a new company these two days. The compan...

Installation tutorial of MySQL 5.1 and 5.7 under Linux

The operating system for the following content is...

The process of installing Docker in Linux system

In this blog, I will walk you through the process...

MySQL 8.0.11 compressed version installation tutorial

This article shares the installation tutorial of ...

An article to help you understand jQuery animation

Table of contents 1. Control the display and hidi...

Vue implements student management function

This article example shares the specific code of ...

Mariadb remote login configuration and problem solving

Preface: The installation process will not be des...

Several ways to schedule backup of MySQL database (comprehensive)

Table of contents 1. mysqldump command to back up...

Nginx request limit configuration method

Nginx is a powerful, high-performance web and rev...