Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

html - 如何在嵌入式CSS中编写a:hover?(How to write a:hover in inline CSS?)

I have a case where I must write inline CSS code, and I want to apply a hover style on an anchor.

(我有一种情况,我必须编写内联CSS代码,并且我想在锚点上应用悬停样式。)

How can I use a:hover in inline CSS inside the HTML style attribute?

(如何在HTML样式属性内的CSS中使用a:hover ?)

Eg you can't reliably use CSS classes in HTML emails.

(例如,您不能在HTML电子邮件中可靠地使用CSS类。)

  ask by Amr Elgarhy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Short answer: you can't.

(简短的答案:您不能。)

Long answer: you shouldn't.

(长答案:你不应该。)

Give it a class name or an id and use stylesheets to apply the style.

(给它一个类名或一个ID,并使用样式表来应用样式。)

:hover is a pseudo-selector and, for CSS , only has meaning within the style sheet.

(:hover是一个伪选择器,对于CSS而言 ,仅在样式表中具有含义。)

There isn't any inline-style equivalent (as it isn't defining the selection criteria).

(没有任何等效的内联样式(因为它没有定义选择标准)。)

Response to the OP's comments:

(回应OP的评论:)

See Totally Pwn CSS with Javascript for a good script on adding CSS rules dynamically.

(有关动态添加CSS规则的良好脚本,请参见带有Javascript的Totally Pwn CSS 。)

Also see Change style sheet for some of the theory on the subject.

(另请参阅更改样式表以获取有关该主题的一些理论。)

Also, don't forget, you can add links to external stylesheets if that's an option.

(另外,不要忘记,如果可以的话,您可以添加到外部样式表的链接。)

For example,

(例如,)

<script type="text/javascript">
  var link = document.createElement("link");
  link.setAttribute("rel","stylesheet");
  link.setAttribute("href","http://wherever.com/yourstylesheet.css");
  var head = document.getElementsByTagName("head")[0];
  head.appendChild(link);
</script>

Caution: the above assumes there is a head section.

(注意:以上假设存在头部 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...