Can I use a CSS class to style a wiki markup link?

I'd like to style a wiki markup link inline using a class defined in the global CSS.

What I was expecting to be able to do in wiki markup is something like this:

[link text|http://link.com|class=classname]

If it helps make it clearer, the equivalent HTML for what I'm trying to do would be this:

<a href="http://link.com" class="classname">link text</a>

Any suggestions?

3 answers

1 accepted

Hallo Dhyana

There are two ways I can think of:

I hope this helps. :)

Cheers, Sarah

Thanks Sarah, I'm actually using Confluence 4.2 but the link is in a global styling area which is why the wiki markup.

I had thought of using the HTML macro but, upon checking the system plugins in the Confluence Admin console, I saw that the {html} macro has been superceded by {html-xhtml} so I'll give that a go.

Thanks so much.

If you dont want to write a macro, you could also use jQuery. Something like this would add a classname attribute to an <a> tag:

AJS.$("a").attr('class','classname');

You add this in your Custom HTML panel in the Admin.

If you wanted to only touch specific anchor tags (such as external links), you could do this:

AJS.$("a[class='external-link']").attr('class','classname');

If you don't mind misusing the link title attribut in a real bad way you could do the following:

Write this into your wiki page:

[link text|http://link.com|green]
[link name|http://link.com|red]

Write this into your CSS export stylesheet

a[title=green] {
color:green;
}
a[title=red] {
color:red;
}

The result on the html page will be this:

&lt;a href="http://link.com" title="green"&gt;link text&lt;/a&gt;
&lt;a href="http://link.com" title="red"&gt;link text&lt;/a&gt;

and the apperarence of the links in the PDF file will be according to the formats in the CSS export stylesheet.

The result will be the same as with a class but off course it is against the real intention of the title attribut.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

524 views 19 11
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you