更改 CSS 链接访问悬停在 html 部分中处于活动状态
我想做一个动态词云,我想知道是否有一种方法可以更改我的 html 部分中的链接颜色,通常你只需在 css 中定义链接颜色,例如:
.tag_cloud { padding: 3px; text-decoration: none; }
.tag_cloud:link { color: #0c3569; }
.tag_cloud:visited { color: #0c3569; }
.tag_cloud:hover { color: #ffffff; background: #0c3569; }
.tag_cloud:active { color: #ffffff; background: #0c3569; }
但我计划做一个词云每个单词都有不同的颜色,又名 link/visited 将颜色定义为动态的,但是有没有办法在 html 中定义 link/visited/hover/active 内联?
我想象它可能是这样的
<a href="something" style="font:arial; ???"word</a>
谢谢。
I want to do a dynamic word cloud and I was wondering if there is a way of changing the link colour in my html section, normally you just define the links colours in css something like:
.tag_cloud { padding: 3px; text-decoration: none; }
.tag_cloud:link { color: #0c3569; }
.tag_cloud:visited { color: #0c3569; }
.tag_cloud:hover { color: #ffffff; background: #0c3569; }
.tag_cloud:active { color: #ffffff; background: #0c3569; }
But I'm planning to do a word cloud were every word has a different colour, aka link/visited will colour will be defined dinamicaly, but is there a way of defining link/visited/hover/active inline in the html?
I Imagine it could be something like this
<a href="something" style="font:arial; ???"word</a>
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不能内联完成,因为 :hover 等是 css 伪选择器,并且不会内联工作,因为这不是它的意图。
但不要害怕使用 css 类 - 无论如何你都需要一些 javascript 来完成这项工作。只需定义您想要使用的类,例如:
然后将它们应用到您的 html 中。这里没什么大不了的。
It can't be done inline since :hover etc. are css pseudo selectors and won't work inline since that is not the intention of it.
But don't be afraid of using css classes - you will need some javascript anyway to make this work. Just define the classes you want to use like:
And than apply them to your html as you wish. No big deal here.
您需要使用一些 JavaScript 来更改悬停时的颜色并检查该项目是否处于活动状态。
或者您可以为每个项目定义一个类/ID(动态)并使用 CSS 定位它们。
You would need to have some JavaScript to change the color on hover and check if the item is active.
Or you could define a class/id (dynamically) for each of the items and target them with CSS.