使用 CSS 样式化 HTML 标题属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17472440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Styling HTML Title attribute using CSS
提问by ColdTuna
I am trying to style the title attribute of a <input type="text">
using CSS. So this is what I did:
我正在尝试<input type="text">
使用 CSS设置标题属性的样式。所以这就是我所做的:
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?
有任何想法吗?
采纳答案by Birdman
You can do a custom solution using CSS3.
您可以使用 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.
看看如何改变锚标签内部的Title属性的样式?. 但我是否建议您使用“数据标题”等自定义字段,以便默认浏览器行为不会干扰您的自定义解决方案。
回答by Akshay Misal
input[type="text"][title]:hover:after {
font-style: italic;
color:gray;
}
回答by Leo
You can add the input's title in <h2></h2>
and then change the property of the title from css like below:
您可以添加输入的标题<h2></h2>
,然后从 css 更改标题的属性,如下所示:
h2 {
font-style: italic;
color: gray;
font-size: 1em;
}