好吧,我有一个HTML表单,我希望能够使用该表单将链接上传到我的数据库,然后在更新的页面上显示链接。一切都很好,但我的问题是,每当从数据库中检索和显示链接时,我都无法对CSS进行更改。例如:
<a href="www.stackoverflow.com">This is a Great Site</a>
是我在表单中输入的内容,它将被保存到数据库中,输出为:
这是一个伟大的网站
我的问题是,除了颜色和其他内联CSS选项之外,我无法更改任何链接样式。我无法更改链接被点击后显示的颜色,或者悬停在上面时的动作。
对此,最简单的方法是什么?有没有一个我缺少的简单CSS解决方法,或者我必须做一些更复杂的事情?
提前谢谢。
假设在固定位置显示这些链接,则向包含这些链接的元素添加一个类。这将避免在添加的每个链接中添加类的麻烦。
<div class="container">
<a href="www.stackoverflow.com">This is a Great Site</a>
</div>
然后你可以用更改这些特定链接的CSS
.container a {
color: green;
}
.container a:hover {
background: yellow;
}
我不明白你的问题。
您的链接是"www.stackoverflow.com"。
您将链接输出为
<a href="www.stackoverflow.com">This is a Great Site</a>
是什么阻止您输出类或样式属性?
<a href="www.stackoverflow.com" class="mylinkclass">This is a Great Site</a>
<a href="www.stackoverflow.com" style="color: red;">This is a Great Site</a>
<a class="myOtherLinkClass" href="www.stackoverflow.com">This is a Great Site</a>
<style>
a.myOtherLinkClass,
a.myOtherLinkClass:hover,
a.myOtherLinkClass:active,
a.myOtherLinkClass:focus{
color: #d5d5d5; //Alternative add !important to the value
}
</style>
这样试试吧。请确保将其放入没有<style>
标记的.css文件中,并将其放在"a"-定义之后。