CSS:穿线颜色与文本颜色不同?
我想要带有红色删除线的灰色文本,但这种样式不起作用:
color: #a0a0a0;
text-decoration: line-through 3px red;
我做错了什么?
I’d like to have gray text with a red strike-through, but this style doesn’t work:
color: #a0a0a0;
text-decoration: line-through 3px red;
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用两个嵌套元素来模拟所需的效果,例如:
jsfiddle
You can simulate the desired effect with two nested elements, e.g.:
jsfiddle
没有额外的 DOM(但由于明显的原因可能不适用于某些布局):
这里有一个 jsfiddle 示例。
With no extra DOM (but may not work for some layouts for obvious reasons):
A jsfiddle example here.
还有另一种方式来看待 CSS2 规范的含义;也就是说,外部文本装饰将设置“line-through”和文本的颜色,但内部颜色声明(在“span”标签中)可用于重置文本颜色。
There is another way of looking at the meaning of the CSS2 specification; and that is the outer text-decoration will set the color of the "line-through" and text, but an inner color declaration (in a 'span' tag) can be used to reset the text color.
不可能用不同的颜色进行穿线。它将采用您使用属性
color
定义的颜色。请参阅http://www.w3.org/TR/CSS2/ text.html#lined-striking-props
编辑:
我想到的是使用带有您喜欢的颜色的 1px * 1px 颜色点的背景图像。
CSS:
HTML:
It's not possible to make a line-through with a different color. It will be in the color you define with property
color
.see http://www.w3.org/TR/CSS2/text.html#lining-striking-props
EDIT:
what came into my mind is to use a background-image with a 1px * 1px color dot in the color you like.
CSS:
HTML:
CSS2 规范说
我想这意味着你不能这样做。
解决方法可能是使用某种边框并解除它?
The CSS2 specs says
I guess that means that you can't do it that way.
A workaround could be using some kind of border, and lifting it?