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?

8
  • 1
    You can't change the style of the title attribute as this is handled by the OS. What you have selects an input element that has a title attribute Commented Jul 4, 2013 at 14:12
  • 2
    possible duplicate of Is it possible to style a title? (and with CSS or js?) Commented Jul 4, 2013 at 14:15
  • You can use JavaScript to change the title property into another thing and finally, you can customize this other thing. Take a look here Commented Jul 4, 2013 at 14:16
  • jQuery FTW on this one. There is no way to style a title attribute with standard CSS Commented Jul 4, 2013 at 16:49
  • possible duplicate of How to change the style of Title attribute inside the anchor tag? Commented Aug 26, 2014 at 15:10

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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;
}

Comments

-1

input[type="text"][title]:hover:after {
  font-style: italic;
  color: red;
}
<input type="text" title="here is a title" />

2 Comments

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.
I made a snippet. It does nothing special in Chrome on a mac in 2020

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.