开发者

Is there any way to use inline styles to define a:visited link style?

So instead doing it using css:

<style type="text/css">
a:visited {
   color: red;
}
</style>

Could it be done using inline code开发者_JS百科. Something like this doesn't work:

<a href="http://google.com" style='a:visited:color:red'>Google.com</a>


You can't do this, the specification (CSS2 here) covers it briefly here:

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 :)


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.

The main CSS for the "a" gives them one color that is not good on that particular and singular area.

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.

Yes, it is definitely a singular and lonely situation, but that is a real case.

Ciao!


Sure you can....

<a href="https://www.yahoo.com/" target="_blank"style="text-decoration: none; border-bottom: 1px solid pink;color:pink !important;">
           some link
        </a>

jfiddle


No, that's not how inline styles work. It is in the specification, however browsers don't seem to support it.


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.


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.)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜