1

Alright, so I have an HTML form and I want to be able to use that form to upload links to my database and then have the links displayed on an updated page. Everything works fine, but my issue is that whenever the link is retrieved and displayed from the database, I am unable to make changes to the CSS. For example:

<a href="www.stackoverflow.com">This is a Great Site</a>

is what I would enter into the form, this would be saved to the database, and the output would be:

This is a Great Site

my issue is, I am unable to change any of the link styles outside of color and other inline CSS options. I am unable to change things like what color it appears after the link has been clicked on, or what kind of action it does when hovered over.

What would be the easiest way to go about this? Is there a simple CSS workaround that I'm missing or am I going have to do something a little bit more complex?

Thanks in advance.

1
  • give a class to link and apply some css on that class Commented Jul 25, 2014 at 6:15

3 Answers 3

2

Assuming you show these links in a fixed place, add a class to the element that contains these links. This will safe you the trouble of adding a class to every link you add.

<div class="container">
  <a href="www.stackoverflow.com">This is a Great Site</a>
</div>

Then you can change the CSS of these specific links with:

.container a {
  color: green;
}

.container a:hover {
  background: yellow;
}
Sign up to request clarification or add additional context in comments.

Comments

1

I don't get your question.

Your link is 'www.stackoverflow.com'.

You output your link as

<a href="www.stackoverflow.com">This is a Great Site</a>

What prevents you from outputing a class or style attribute?

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

Comments

1
<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>

Try it like this. Be sure to put this into your .css-File without the <style> tags and put it after your "a"-Definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.