A CSS attribute selector using a string value match (e. g. a[href="https://dummy2.org"]) or a CSS child combinator (e. g. div.my-box > p) cannot be used in a Confluence User Macro.
This is because Confluence erroneously replaces the symbols used here (double quotes and greater than symbol) by their HTML entities (" and >). As a result, the CSS code does not work.
Does anyone know a workaround for this, especially for the child combinator?
Below are a few details.
Example: From this code in a User Macro ...
<style>
.wiki-content div.my-box > p { font-weight: bold; }
.wiki-content a[href="https://dummy2.org"] { color: red; }
.my-box {border: 2pt solid black; }
</style>
... Confluence generates the following HTML code:
<style>
.wiki-content div.my-box > p { font-weight: bold; }
.wiki-content a[href="https://dummy2.org"] { color: red; }
.my-box {border: 2pt solid black; }
</style>
I found out that this bug has already been discussed several times in the Atlassian Community (e. g. 2015, 2017, 2018, 2020) or in Atlassian JAC (2016), unfortunately without success: At least in version 8.4.5 it is still present.
I haven't given up hope that this bug will actually be fixed one day. But until then, the question is whether there are any workarounds. These are the results I found on the sites mentioned above:
My own tests have shown the following:
In the meantime, I have found a solution myself by adding a CDATA section to the CSS code.
Example: From this code in a User Macro ...
<style>
/* <![CDATA[ */
.wiki-content div.my-box > p { font-weight: bold; }
.wiki-content a[href="https://dummy2.org"] { color: red; }
.my-box {border: 2pt solid black; }
/* ]]> */
</style>
... Confluence generates the following HTML code ...
<style>
/* <![CDATA[ */
.wiki-content div.my-box > p { font-weight: bold; }
.wiki-content a[href="https://dummy2.org"] { color: red; }
.my-box {border: 2pt solid black; }
/* ]]> */
</style>
... which is exactly what we wanted to achieve.
Explanation
Summary
The error in Confluence described above can be circumvented by an additional CDATA section shown below and thus enables the use of any CSS instructions in a Confluence user macro (tested in Confluence Data Center 8.4.5). 😃
<style>
/* <![CDATA[ */
/* Your CSS code goes here. */
/* ]]> */
</style>
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.