Html 有没有办法使用内联样式来定义:访问链接样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3329675/
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
Is there any way to use inline styles to define a:visited link style?
提问by Georgy
So instead doing it using css:
所以改用css来做:
<style type="text/css">
a:visited {
color: red;
}
</style>
Could it be done using inline code. Something like this doesn't work:
是否可以使用内联代码完成。像这样的东西不起作用:
<a href="http://google.com" style='a:visited:color:red'>Google.com</a>
采纳答案by Nick Craver
You can't do this, the specification (CSS2 here) covers it briefly here:
您不能这样做,规范(此处为 CSS2)在此处简要介绍了它:
Neither pseudo-elements nor pseudo-classes appear in the document source or document tree.
伪元素和伪类都不会出现在文档源或文档树中。
:visited
along with the others modifiers are all pseudo-classes, and there was never a standard syntax setup to do what you're trying. Honestly this is the first time I've ever seen it requested, so I don't think it'll be added to the specification anytime soon...sorry that answer sucks, but it is what it is :)
:visited
与其他修饰符一起都是伪类,并且从来没有标准的语法设置来执行您正在尝试的操作。老实说,这是我第一次看到它被要求,所以我认为它不会很快被添加到规范中......对不起,这个答案很糟糕,但它就是这样:)
回答by joshpierro
回答by Robert
Just to add one motivation to achieve this inline style for the various a href states: in some page it could appear text with link in one are where the background is different from the overall background.
只是为了为各种 a href 状态添加一个实现这种内联样式的动机:在某些页面中,它可能会出现带有链接的文本,其中背景与整体背景不同。
The main CSS for the "a" gives them one color that is not good on that particular and singular area.
“a”的主要 CSS 为它们提供了一种在该特定和单一区域上不好的颜色。
For this reason, to give the user the idea that the link is a link, you need to color that link differently from the others.
出于这个原因,为了让用户认为该链接是一个链接,您需要将该链接的颜色与其他链接不同。
For me it worked to set some style="color: #5070BB;"
inside the <a href=".."
tag, but maybe that neither the a:visited nor the a:hover colors are good for that background and it would be useful to set them inline.
对我来说,它可以style="color: #5070BB;"
在<a href=".."
标签内设置一些,但也许 a:visited 和 a:hover 颜色都不适合该背景,将它们设置为内联会很有用。
Yes, it is definitely a singular and lonely situation, but that is a real case.
是的,这绝对是一种奇异而孤独的情况,但这是一个真实的案例。
Ciao!
再见!
回答by cherouvim
No. Pseduoclasses (e.g :first-child, :hover) are used as selectors based on behavior and relation to other DOM elements. Inline styles contain rules. Even if at some point browsers do support this, it'll feel weird.
否。伪类(例如:first-child、:hover)用作基于行为和与其他 DOM 元素的关系的选择器。内联样式包含规则。即使在某些时候浏览器确实支持这一点,它也会感觉很奇怪。
回答by Aaron Wallentine
As far as I know, it isn't supported ... but to add some clarification for the reason for wanting to do this, since it would definitely be the sub-optimal way to do it on a regular web page, the reason would be to use in HTML email, which, except for certain good email clients, does not support regular style sheets, so it's necessary to define all styles inline to ensure good support across email clients (Gmail and Outlook (ugh) come to mind.)
据我所知,它不受支持......但要为想要这样做的原因添加一些说明,因为它肯定是在常规网页上执行此操作的次优方式,原因是将在 HTML 电子邮件中使用,除了某些好的电子邮件客户端,它不支持常规样式表,因此有必要定义所有样式内联以确保跨电子邮件客户端的良好支持(Gmail 和 Outlook(呃)浮现在脑海中。)
Of course, it's possible to use some other program that lets you import a stylesheet and automatically convert it to inline styles, which is much easier to manage (that's what I do), but you're still using inline styles in the end-analysis.
当然,可以使用其他一些程序来导入样式表并自动将其转换为内联样式,这更容易管理(这就是我所做的),但是您仍然在最终分析中使用内联样式.
回答by Ben Shelock
No, that's not how inline styles work. It is in the specification, however browsers don't seem to support it.
不,内联样式不是这样工作的。它在规范中,但是浏览器似乎不支持它。