8

I am trying to style the title attribute of a <input type="text"> using CSS. So this is what I did:

input[type="text"][title] {
    font-style: italic;
    color: gray;
}

It works okay, but when I enter data into the field, the data is gray and italic. I want the data (value) to be normal and black, and only the title to be italic and gray.

Any ideas?

Caio Mars
  • 1,997
  • 4
  • 27
  • 35

3 Answers3

4

You can do a custom solution using CSS3.

Take a look at How to change the style of Title attribute inside the anchor tag?. But might I suggest that you use a custom field like 'data-title' so the default browser behaviour doesn't interfere with your custom solution.

Community
  • 1
  • 1
Birdman
  • 724
  • 5
  • 9
1

input[type="text"][title]:hover:after {
  font-style: italic;
  color: red;
}
<input type="text" title="here is a title" />
mplungjan
  • 155,085
  • 27
  • 166
  • 222
  • 3
    Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually wont help the OP to understand their problem. – Drenmi Jan 04 '16 at 17:26
  • I made a snippet. It does nothing special in Chrome on a mac in 2020 – mplungjan Dec 13 '20 at 14:37
1

You can add the input's title in <h2></h2> and then change the property of the title from css like below:

h2 {
    font-style: italic;
    color: gray;
    font-size: 1em;
}
Leo
  • 4,897
  • 5
  • 28
  • 51